Cannot Send PHP Mail after Ubuntu Upgrade

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

.
closeThis post was last updated 9 years 4 months 25 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.

  2. Yasiru says:

    I’m experiencing same issue but unfortunately I cannot using this solution. Because my server is shared with several users with multiple websites. So I think allowing root for users may case security issue.

  3. Alex says:

    Oh, it not work in Ubuntu 20.4 🙁
    nano /etc/apache2/mods-available/mpm_prefork.conf can’t contain LimitUIDRange 0 2000 parametrs.

    my mpm_prefork.conf :

    # prefork MPM
    # StartServers: number of server processes to start
    # MinSpareServers: minimum number of server processes which are kept spare
    # MaxSpareServers: maximum number of server processes which are kept spare
    # MaxRequestWorkers: maximum number of server processes allowed to start
    # MaxConnectionsPerChild: maximum number of requests a server process serves

    StartServers 5
    MinSpareServers 5
    MaxSpareServers 10
    MaxRequestWorkers 150
    MaxConnectionsPerChild 0

    # vim: syntax=apache ts=4 sw=4 sts=4 sr noet

This site uses Akismet to reduce spam. Learn how your comment data is processed.