It took me a whole evening to figure it out. I am sharing it here, hope it can help others.

I got the email error. However, my php.ini is configured correctly, because phpinfo() shows smtp server as "localhost" and port number is correct as well. smtp is running on the server. The problem baffled me for a long time.

I finally found a help post from my ISP knowledge base, it says like this:

Add the following code to the top of your email script if your mail script continues to fail.

// Please specify your Mail Server - Example:

// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.

// Please specify the return address to use
ini_set('sendmail_from', '');

In my case, I modified as following

function drupal_mail_send($message) {
    ini_set("SMTP","");  // this line 184 for me  
    return mail(
      join("\n", $mimeheaders)

It worked for me. Hope it can help you.


newbuntu’s picture

Can someone with admin right help me to change my stmp server name here? I didn't intend to put it there. Thanks!

dww’s picture

My professional services are available through 3281d Consulting

JohnMorris’s picture


Great note; I can verify that it works like a charm. Thank you for posting. FYI, other folks, here is some additional information:

PROBLEM: Want to have email working on a local LAN, from Drupal. For now, just have the ability to send emails -- e.g. of a new book page -- to other family members.

EMAIL SERVER: You need an email server to do this. There are lots of free ones. I'm using alt-N MDaemon, which is free for up to five accounts. It is installed on our private LAN interface on the hub machine (which has a separate interface to the Internet).

WAMP STACK: Drupal is working on top of the XAMPP stack. You have to edit the php.ini (or php5.ini) files to make sure that your email is expected on the interface above.

SETTING DRUPAL PROPERLY: As has been pointed out in many other posts, just doing all the above still leaves Drupal email in a non-working state. You have to implement Ubuntu's solution (which is also referenceable elsewhere).

HOW TO DO IT: Do is exactly as Ubuntu says, above. In my case, it was actually still "line 184". In case you find the above intimidating, the ONLY thing you need to add is the single line: ini_set("SMTP",""); everything else is the same.

SPECIFICALLY: In my case, the new line is: ini_set("SMTP","");

Why bother with this note? Because verification is sometimes helpful when you are searching for a solution. And with more info here, I'm thinking someone may have a search term that helps them end up here.

Thanks again Ubuntu!


coreyp_1’s picture


You can put the same line in your settings.php file (where other calls to ini_set() occur).

That being said, thanks for providing the info.

- Corey

JohnMorris’s picture


Thanks for your warning -- it is much appreciated -- and likely needed to (esp. if I update my Drupal at somepoint as is likely) Um, could you be more specific, i.e. much much more specific?

A lot of us are operating at the limit of our technical capability, although I personally believe that Drupal can be used without knowing PHP or being a programmer -- and my experience over a year and a half is that Drupal is usable and stable (and does what I think is not easily available anywhere else). Nevertheless problems such as the email problem outlined here sometimes have overly technical solutions. I think I can figure this out based on your note, however additional info would be helpful I think:

1) What is a core file? Is settings.php not also a core file?
2) Exactly where in settings.php should and how the setting be changed exactly?
3) And why would the file edit not override that?
4) And while we are at it, is there some documentation somewhere which brings together ALL the information and settings necessary to setting up proper email? (It would be nice to have it written in a way that makes serious PHP knowledge unnecessary. I believe that email can be set up in about 5 minutes if you know what to do -- but as the originator of this thread found out, it takes a whole evening of reading to get to that 5 minutes.)
5) Is there anything else we need to know?

Many thanks if you feel you are able to add a little more. I originally added my own comment, not to mislead, but because there seemed to be a solution. So now, with all this searchable material, people with the same problem can come back and have the info they need.

All the best,


coreyp_1’s picture

I don't mind sharing more information so as to help you use Drupal better. :)

Let me try to address each of your questions:

  1. A core file is a file that is part of the standard Drupal installation... the part that you download from the front page.

    Drupal's philosophy is to be so modular in design that a programmer can change how Drupal behaves by adding modules. If you are trying to get Drupal to do something, but you have to change code within the Drupal system itself, then either (A) you're doing it wrong, or (B) Drupal core needs to be changed to allow for a module to interact with it at that point.

    Most of the time, I've found out that I'm just doing it wrong. If, however, the problem lies within Drupal's core code, then the deficiencies in Drupal's design are brought to the attention of the community, and the core code is re-worked to allow for the additional functionality. That is how we get new versions of Drupal (4.7, 5.x, 6.x, 7.x, etc.).

  2. settings.php is not a core file per se, because it is meant to be edited. It is found in the /sites/default directory.

    If you read through the file, it has a lot of comments describing different changes that you can make in that file. It is the one file in the Drupal installation where additions are not only acceptable, but necessary for the functionality of your website. For example, the database connection information is stored in the settings.php file.

    In this case, we are needing to add an ini_set() declaration to the settings.php file. By reading through the file (here is what a default one looks like), you can get a feel for the information it contains. One area in particular makes a lot of calls to ini_set(). It looks like this:

     * PHP settings:
     * To see what PHP settings are possible, including whether they can
     * be set at runtime (ie., when ini_set() occurs), read the PHP
     * documentation at
     * and take a look at the .htaccess file to see which non-runtime
     * settings are used there. Settings defined here should not be
     * duplicated there so as to avoid conflict issues.
    ini_set('arg_separator.output',     '&');
    ini_set('magic_quotes_runtime',     0);
    ini_set('magic_quotes_sybase',      0);
    ini_set('session.cache_expire',     200000);
    ini_set('session.cache_limiter',    'none');
    ini_set('session.cookie_lifetime',  2000000);
    ini_set('session.gc_maxlifetime',   200000);
    ini_set('session.save_handler',     'user');
    ini_set('session.use_only_cookies', 1);
    ini_set('session.use_trans_sid',    0);
    ini_set('url_rewriter.tags',        '');

    Here is where you would add the ini_set() for the SMTP settings.

  3. And why would the file edit not override that?

    Well, actually, if you put an ini_set() declaration in, it probably would override it. But there was no ini_set() in at all... so then why should someone hack the file to add it in? If you put the declaration in settings.php (which is processed at the very beginning of a Drupal page load) then the variable will already be set.

  4. This is the first time that I have seen a post about the SMTP configuration problem, and, to tell you the truth, I have never had this issue before... on ANY of the server environments that I have worked on over the years. I assume that someone would only have this problem when PHP itself was not configured correctly, as in this case.
  5. I can't really think of anything else to add.

I hope that this information was helpful.

- Corey

JohnMorris’s picture


Great info! It is really helpful, and I'm sure others arriving here by search will be able to use as well. Thanks for taking the time!


srvictor’s picture


mkzaman’s picture

Thnaks Corey and John for this post.

cowboysdude’s picture

Without hacking the core files how do I get drupal to send email? I am using a home server and have to use my ISP to send my mail via smtp... so that means I would need to specify a server, login and password.


wml2005’s picture

I've been lost for about six hours trying to get this email script to work. Thank you! Your solution worked perfectly.

anob’s picture

thank you for this post.
really helped me to get the application up in no time
here is a link for finding out your mail server

// Please specify your Mail Server - Example:

kingsleyben’s picture

This fixed my problem. I'm running Windows 7 with XAMPP. Thanks a lot!

nakedeyez’s picture

thank you for this post.