Cannot Send PHP Mail after Ubuntu Upgrade

created October 29, 2014, last updated June 5, 2016.

.
closeThis post was last updated 3 years 24 days ago, some of the information contained here may no longer be actual and any referenced software versions may have been updated!

I recently made a list of problems experienced after upgrading from Ubuntu 12.04 LTS to Ubuntu 14.04.1 LTS, an additional problem that finally came to light about a week later was that mail sent from php scripts using the php mail() function stopped working.

php mail() returns FALSE

My Ubuntu mail setup uses sendmail with exim4. After the upgrade I was occasionally seeing the following exim4 error

2014-10-29 08:00:50 unable to set gid=33 or uid=0 (euid=0): forcing real = effective

Normal email was working fine and php mail from the command line, or cron jobs was also working fine. It was only email sent via web sites i.e. with online forms using the php mail command i.e.

$mail=\mail($email, $subject, $message);

$mail would always return FALSE, and an exim4 error would be logged.

The exim error points to a permissions problem with the Apache user group – www-data in Ubuntu. Group ID 33 is www-data.

After googling around for a while and looking at various configuration options in php.ini the resolution lay with the Apache ITK MPM module.

It seems that a default configuration in this module with Apache 2.7 has some kind of influence on the permissions associated with the www-data user/group when communicating with exim4.

The fix is to explicitly define the ITK MPM module LimitUIDRange parameter in the /etc/apache2/mods-available/mpm_prefork.conf module configuration to something like

LimitUIDRange 0 2000

Restart Apache and Exim 4 and PHP mail via Apache works again.

 

Comments

  1. Jiří says:

    Thank you!

    That helped!

    Further readers, please NOTE that you have to set the “LimitUIDRange” parameter, not the “LimitGIDRange”, which is bold in the text above.