Reputation: 109
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=<[email protected]>, size=1468, nrcpt=1 (queue active)
Oct 22 00:07:17 doodle postfix/local[26486]: 60AB5688811C: to=<php_mail_handler@localhost>, orig_to=<[email protected]>, 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
Upvotes: 1
Views: 975
Reputation: 9
if Michaels solution won´t work, instead of using
$f = fopen('php.txt','a+');
fwrite($f,date('Y-m-d h:i:s')."\n");
try
system("echo 'it works!' > /home/yourname/php.txt");
On my fresh wheezy installation postfix's php CLI call was not able to access fopen and fwrite.
Upvotes: 1
Reputation: 109
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.
Upvotes: 3
Reputation: 270637
Add a shebang to the top of the PHP script, make it executable, and remove the php
from the pipe call. This avoids any problems postfix may have resolving the path to the PHP binary.
// Top of the PHP file...
#!/usr/bin/php -q
# Alias file:
php_mail_handler: "|/home/doodle/htdocs/mail_handler.php"
# make it executable
chmod +x /home/doodle/htdocs/mail_handler.php
Upvotes: 0