我目前有一个Postfix服务在运行,它可以很好地发送和接收电子邮件。我正在尝试将"测试"地址别名为运行PHP脚本。请参阅以下别名文件的摘录。
test: "| php -q /var/blahblahblah/php/test.php"
以下是test.php的内容。它似乎在命令行中正确运行。
#!/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);
?>
下面是mail.log的摘录,显示了感兴趣的主要行。
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
请注意括号中的delivery-to-maildir位。这是不是应该说"交付给脚本"之类的话?
目前,所有文件都设置为777权限,别名文件通过使用sudo newaliases
保持更新
PHP脚本似乎没有被正确调用,但我在任何日志中都没有得到"错误"。
以前有人经历过或解决过这个问题吗?
来自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.
所以我认为这就是
test: |"php -q /var/blahblahblah/php/test.php"