从命令行执行时,如何阻止PHP返回标头?

时间:2010-03-14 20:09:23

标签: php command-line email pipe exim

这可能是一个荒谬的问题,但它一直困扰着我。 我有一个邮件转发器管道传输到PHP脚本,它收到完美,但我有以下错误邮寄给我立即:

A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. The following address(es) failed:

  pipe to |/home/[webroot]/public_html/external/mobile/email.php
    generated by mobile@[mydomain]

The following text was generated during the delivery attempt:

X-Powered-By: PHP/5.2.13 
Content-type: text/html

正如您所看到的,Exim认为标题响应是我脚本的错误。该脚本可以从 php:// stdin 完全接收电子邮件,但Exim会快速回复错误。

另外,

  • 它是从控制台运行的,而不是Apache,所以HTAccess或配置Apache很可能什么都不做。
  • 我找不到任何解决方案,或任何有同样问题的人。

所以我的问题是:如何摆脱这两个标题?

谢谢, 〜乔尼

编辑,来源:

    #!/usr/bin/php
<?php
    $fd = fopen("php://stdin", "r");
        $email = "";
        while (!feof($fd)) {
         $email .= fread($fd, 1024);
        }
        fclose($fd);

        $dat = fopen(dirname(__FILE__).'/test.txt', 'w');
        fwrite($dat, $email);
        fclose($dat);

2 个答案:

答案 0 :(得分:14)

看起来你正在运行php-cgi而你需要php-cli(只是“php”)。运行php -v以确保。如果是这种情况,请尝试“-q”选项。

答案 1 :(得分:1)

有同样的问题。我的主人告诉我,我可以使用php-5.4-cli(通常我使用的是php-5.4)。

添加-cli为我工作。