使用 postfix 别名和 MySQL 进行管道传输
我正在尝试将传入的电子邮件重定向到 php 脚本的特定电子邮件地址。我正在使用 Postfix,其地址和域信息存储在 MySql 中。因为我相信管道不能从 mysql 表完成,所以地址在表中与系统别名配对:
在 /etc/aliases 中:
#Other aliases
php_mail_handler: "| /usr/bin/php -q /home/mysite/htdocs/mail_handler.php"
这似乎在一定程度上有效,因为 /var/log/mail.info 包含以下:
Jul 17 14:53:29 mysite postfix/qmgr[21974]: 39F726888003: from=<[email protected]>, size=1476, nrcpt=1 (queue active)
Jul 17 14:53:30 mysite postfix/local[21981]: 39F726888003: to=<php_mail_handler@localhost>, orig_to=<[email protected]>, relay=local, delay=0.95, delays=0.28/0.01/0/0.66, dsn=2.0.0, status=sent (delivered to command: /usr/bin/php -q /home/mysite/htdocs/mail_handler.php)
但是,php 脚本永远不会执行(它将时间戳和 stdin 上的任何内容写入日志文件)。该脚本在从命令行或通过 apache 调用时有效。它的代码如下:
<?php
$f = fopen('php_handler_log.txt','a+');
$data = file_get_contents("php://stdin");
fwrite($f,date('Y-m-d h:i:s').': '.$data."\n");
fclose($f);
?>
有谁知道它为什么可能不起作用或者如何调试它?由于 php 错误日志中没有显示任何错误,因此我在 CLI 的 php.ini 中指定了该错误。
非常感谢,
马特
I am trying to get incoming email to a specific email address redirected to a php script. I am using Postfix with address and domain information stored in MySql. As I believe the piping cannot be done from the mysql table, the address is paired within the table with a system alias:
In /etc/aliases:
#Other aliases
php_mail_handler: "| /usr/bin/php -q /home/mysite/htdocs/mail_handler.php"
This seems to work to a certain extent as /var/log/mail.info contains the following:
Jul 17 14:53:29 mysite postfix/qmgr[21974]: 39F726888003: from=<[email protected]>, size=1476, nrcpt=1 (queue active)
Jul 17 14:53:30 mysite postfix/local[21981]: 39F726888003: to=<php_mail_handler@localhost>, orig_to=<[email protected]>, relay=local, delay=0.95, delays=0.28/0.01/0/0.66, dsn=2.0.0, status=sent (delivered to command: /usr/bin/php -q /home/mysite/htdocs/mail_handler.php)
However, the php script never executes (it writes the timestamp and anything on stdin to a log file). The script works when called from the command line or via apache. Its code is as follows:
<?php
$f = fopen('php_handler_log.txt','a+');
$data = file_get_contents("php://stdin");
fwrite($f,date('Y-m-d h:i:s').': '.$data."\n");
fclose($f);
?>
Does anyone have any ideas about why it might not be working or how even to debug it? As no errors are showing-up in the php error log I have specified in the CLI's php.ini.
Many thanks,
Mat
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试使用无人用户在命令行上执行脚本?
然后在运行测试时尝试使用现有的电子邮件地址,您可能会在发件人电子邮件中收到部分错误。
Did you try to execute the script on the command line with user nobody?
Then try to use an existing email address when running the test, you'll maybe get back in the sender email a part of the errors.