Search code examples
phppostfix-mta

Mail to PHP Seems to fail, but where?


I have set up mail to an incoming address to forward in postfix to an alias for a php script. I think this is working because of the following entries in mail.log:

Oct 22 00:07:02 doodle postfix/qmgr[19688]: 60AB5688811C: from=<me@gmail.com>, size=1468, nrcpt=1 (queue active)
Oct 22 00:07:17 doodle postfix/local[26486]: 60AB5688811C: to=<php_mail_handler@localhost>, orig_to=<php@doodle.com>, relay=local, delay=16, delays=1.8/0.1/0/14, dsn=2.0.0, status=sent (delivered to command:  php /home/doodle/htdocs/mail_handler.php)
Oct 22 00:07:17 doodle postfix/qmgr[19688]: 60AB5688811C: removed

This seems to suggest that postfix is delivering it to the script. I get no error bounced back to my email, and yet the script does not execute (it should write the time to a file). The script works from the command line and from web execution. Its code is:

<?php
$f = fopen('php.txt','a+');

fwrite($f,date('Y-m-d h:i:s')."\n");
fclose($f);

?>

My aliases file contains:

php_mail_handler: "| php /home.doodle/htdocs/mail_handler.php"

My initial problem is that it is failing silently - mail.log, as can be seen above, seems to suggest all is well. Is there a log that would tell me why php fails to execute that I can check? Any idea with regard to the general problem? Vaguely similar posts in forums for sendmail seem to say that that requires symlinks in smrsh, but I have found nothing saying that postfix requires this.

Any help would be greatly appreciated.

Mat


Solution

  • Revisiting this years later, I have come across again and solved the same problem:

    Postfix uses the unprivileged user "nobody" to execute piped commands from to aliases. To overcome this, create a user with the required privileges and assign to default_privs in main.cf (you will need to add the line):

    default_privs = mynewuser

    Restart and you are away.