PHP script not running when aliased to an email address in Postfix

Go To StackoverFlow.com

1

I've currently got a Postfix service running which sends and receives emails fine. I'm trying to alias the "test" address to run a PHP script. See excerpt of aliases file below.

test: "| php -q /var/blahblahblah/php/test.php"

Here is the contents of test.php. This seems to run correctly in command line.

#!/usr/bin/php
<?php
$file = fopen("/tmp/postfixtest", "a");
fwrite($file, "Script successfully ran at ".date("Y-m-d H:i:s")."\n");
fclose($file);
?>

Below is an excerpt of the mail.log showing the main lines of interest.

postfix/qmgr[3427]: 02BE9472A: from=<sender@email.com>, size=1681, nrcpt=1 (queue active)
postfix/virtual[3435]: 02BE9472A: to=<test@domain.com>, relay=virtual, delay=0.45, delays=0.42/0.01/0/0.02, dsn=2.0.0, status=sent (delivered to maildir)
postfix/qmgr[3427]: 02BE9472A: removed

Note the delivered to maildir bit in brackets. Is this supposed to say something like "delivered to script"?

All the files are set to 777 permissions for now and the aliases files are kept updated by using sudo newaliases

It seems as if the PHP script isn't being called properly but I get no 'errors' in any of the logs.

Has anyone experienced or fixed this before?

2012-04-04 02:51
by Blates
Did you reload the alias file after adding this? Some installations have a command newaliases or newaliases.postfix, or just restart postfix - Michael Berkowski 2012-04-04 02:54
I wouldn't expect it to fail, but I've never seen a pipe alias with spaces. Try removing the leading space test: "|php -q /path/to/script.php"Michael Berkowski 2012-04-04 02:55


1

from man aliases

|command
       Mail  is piped into command. Commands that contain special char-
       acters, such as whitespace, should be  enclosed  between  double
       quotes. See local(8) for details of delivery to command.

       When  the  command  fails, a limited amount of command output is
       mailed back to the  sender.   The  file  /usr/include/sysexits.h
       defines  the expected exit status codes. For example, use "|exit
       67" to simulate a "user unknown" error, and "|exit 0" to  imple-
       ment an expensive black hole.

so I would expect this is what is meant:

test: |"php -q /var/blahblahblah/php/test.php"
2012-04-04 03:15
by dldnh
Ads