Configuring PHP to resolve the "Error sending email" message

This article is based on experience with a Linux system running an Apache web server, but the problems and solutions apply to many other Linux and non-Linux environments.

This won't solve all problems that cause the "Error sending email" message, but this describes some solutions to a couple of common causes.

IMPORTANT NOTE: Some web servers, including Apache, require you to reload the server for changes to php.ini to have any effect.

Internet email has two "from" addresses: the header "From" address and the "envelope-from" address. The default PHP and sendmail setups use the current username for both, but many configurations don't provide an email address for each username and system account, in which case both "from" addresses may need correcting to help resolve the problems that result in the "Error sending email" message.

Bogus "From" header address

By default, the PHP mail() function uses the current username in the message header "From" address. The solution is to change the following line in php.ini:

sendmail_from = "webmaster@MYDOMAIN.TLD"

Bogus "envelope-from" address

Just as with the "From" address, by default sendmail makes the same assumption that PHP does, that the current user has an email address. PHP calls sendmail with default arguments and, by default, sendmail uses the current user name for the "envelope-from" address. This problem can also be resolved with a change to php.ini:

sendmail_path = "/usr/lib/sendmail -t -f webmaster@MYDOMAIN.TLD"

What Solved My "Error sending email" Message

stevo_inco - September 16, 2009 - 00:36

I received the message above after installing Drupal for the first time. It turned out to be a permission issue with Sendmail. The Apache user (www-data) didn't have read access to my mail configuration (/etc/postfix/main.cf and /etc/postfix/dynamicmaps.cf) and would fail on start. I resolved the problem by adding the user 'www-data' to the 'mail' group (/etc/group), and assigning the 'mail' group to the two configuration files already mentioned.

I imagine that based on your configuration, Sendmail may need read access to other files on your system, but I'm not an expert on the matter. The failed read access was in my mail logs, so you might try there if it's not working.

--
Steve Cox

 
 

Drupal is a registered trademark of Dries Buytaert.