php - Sendmail 管道到 PHP : Could not open input file

标签 php pipe sendmail file-permissions user-permissions

我已经安装了 sendmail 并希望将收到的电子邮件通过管道传输到 php。

每次我向我的服务器发送电子邮件时,我都会收到一封带有错误消息的电子邮件:

could not open input file: /root/fw/catcher.php 554 5.3.0 unknown mailer error 1

我认为具有 catcher.php 权限的内容是错误的,但我自己无法弄清楚。

Sendmail 已安装,我已添加别名:

root: "|/usr/bin/php /root/fw/catcher.php"

权限(在 chmod 777 之后;我尝试了 chmod 777chmod 755 但都不起作用):

drwxrwxrwx 2 root root 4096 Jul 20 14:27 fw
-rwxrwxrwx 1 root root   45 Jul 20 14:27 catcher.php

catcher.php(将行尾转换为 Unix 风格):

#!/usr/bin/php
<?php echo 'Test'; exit(0); ?>

通过 cli 执行我的 php 文件工作正常。所有这些命令都有效:

/usr/bin/php /root/fw/catcher.php
/usr/bin/php7.3 /root/fw/catcher.php
php /root/fw/catcher.php
php7.3 /root/fw/catcher.php

我认为sendmail的权限有问题。

最佳答案

错误“无法打开输入文件”表示由于某种原因无法读取文件。

请按照以下步骤检查:

  1. converted line endings to Unix style

我不知道你是如何检查这个的,但你可以尝试使用 dos2unix, as described in this link 重做这个

dos2unix catcher.php > newcatcher.php

然后比较文件大小。

  1. 可能是 BOM 破坏了脚本,如所述here , shebang 行 "#!/usr/bin/php" 告诉系统在调用这样的脚本时需要运行哪个解释器。

If the script is encoded in UTF-8, one may be tempted to include a BOM at the beginning. But actually the "#!" characters are not just characters. They are in fact a magic number that happens to be composed out of two ASCII characters. If you put something (like a BOM) before those characters, then the file will look like it had a different magic number and that can lead to problems.

脚本将通过 cli 运行,因为您明确告诉它要使用哪个解释器:phpphp7.3:

php /root/fw/catcher.php
php7.3 /root/fw/catcher.php

要从文件开头删除 BOM,请尝试 this :

dos2unix catcher.php

尝试运行 /root/fw/catcher.php,作为 shell 脚本而不使用 php 或 php7.3 可执行文件。从终端运行:

./root/fw/catcher.php

关于php - Sendmail 管道到 PHP : Could not open input file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57125764/

相关文章:

php - 在数据库中创建3个表(检索数据php/mysql)

python - 尝试将命令行输出保存到文件时出错

c++ - 为什么当管道写入 stdout 时 write() 到管道退出程序?

awk - 将系统命令的输出分配给变量

php - INNER JOIN 中 SELECT IF 的 Mysql 结果

php - 使用 xampp 打开一个 php 文件

Javascript:如何更改 contenteditable div 占位符颜色

c# - SmtpClient无法发送;雷鸟可以

centos - Sendmail 命令行问题

image - 单击打开用户邮件的图像,将其发送到我的电子邮件地址