邮件到 PHP 似乎失败了,但在哪里?

发布于 2024-12-11 07:14:12 字数 1291 浏览 0 评论 0原文

我已经将邮件设置为传入地址,以在 postfix 中转发到 php 脚本的别名。我认为这是有效的,因为 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

这似乎表明 postfix 正在将其传递给脚本。我的电子邮件没有收到任何错误退回,但脚本没有执行(它应该将时间写入文件)。该脚本通过命令行和 Web 执行运行。它的代码是:

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

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

?>

我的别名文件包含:

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

我最初的问题是它默默地失败 - mail.log,如上面所示,似乎表明一切都很好。是否有一个日志可以告诉我为什么 php 无法执行,我可以检查?关于一般问题有什么想法吗? sendmail 论坛中模糊相似的帖子似乎说这需要 smrsh 中的符号链接,但我没有发现任何内容说 postfix 需要这个。

任何帮助将不胜感激。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

独闯女儿国 2024-12-18 07:14:12

几年后重温,我再次遇到并解决了同样的问题:

Postfix 使用非特权用户“nobody”从别名执行管道命令。要克服这个问题,请创建一个具有所需权限的用户,并分配给 main.cf 中的 default_privs(您需要添加以下行):

default_privs = mynewuser

重新启动即可离开。

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.

摇划花蜜的午后 2024-12-18 07:14:12

如果 Michaels 的解决方案不起作用,请不要使用

$f = fopen('php.txt','a+');
fwrite($f,date('Y-m-d h:i:s')."\n");

try

system("echo 'it works!' > /home/yourname/php.txt");

在我新安装的 postfix 的 php CLI 上调用无法访问 fopen 和 fwrite。

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.

束缚m 2024-12-18 07:14:12

将 shebang 添加到 PHP 脚本的顶部,使其可执行,然后从管道调用中删除 php。这可以避免 postfix 解析 PHP 二进制文件路径时可能出现的任何问题。

// 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文