php - 从命令行执行时如何阻止 PHP 返回 header ?

标签 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 很可能什么都不做。
  • 我找不到任何解决方案,也找不到任何有相同问题的人。

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

谢谢, ~强尼

编辑,来源:

    #!/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);

最佳答案

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

关于php - 从命令行执行时如何阻止 PHP 返回 header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2443575/

相关文章:

email - Exchange 2010/13 - 按类别搜索邮件并将其设置为敏感度 :private

php - 检查数据库 php 中是否已存在值

PHP UPDATE 'name' 中的未知列 'field list'

php - 需要提交表单两次才能使用 jQuery AJAX 正确发布

linux - 观察一个文件的变化

java - 使用 Velocity 模板生成的电子邮件中的绝对 URL

javascript - 表单重新加载页面,提交时不发送数据

php - 如何获取在其他页面上选择的值?

windows - findstr.exe 不工作

java - 如何使用 Java 代码运行 Java 包内的批处理文件?