电子邮件管道到脚本可以工作,但仍然会返回反弹邮件

时间:2013-09-15 06:30:37

标签: php email pipe

这是我用于拦截的PHP脚本:

#!/usr/local/bin/php -q
<?php
//Listen to incoming e-mails
$sock = fopen("php://stdin", 'r');
$email = '';

//Read e-mail into buffer
while (!feof($sock))
{
    $email .= fread($sock, 1024);
}

//Close socket
fclose($sock);

emailPoster('email@address.com', "message");

function emailPoster( $to, $email )
{
    $subject = "Email Intercepted";
    $body = $message;
    $headers    = "To: {$to}\r\n";
    $headers    .= "From: noreply@example.com\r\n";
    $headers    .= "Subject: {$subject}\r\n";
    $headers    .= "Reply-To: noreply@example.com\r\n";
    $headers    .= "Return-Path: noreply@example.com\r\n";
    $headers    .= "MIME-Version: 1.0\r\n";
    $headers    .= "Date: " . date("r") . "\r\n";
    $headers    .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    $sender     = '-fnoreply@example.com';
    if (mail($to, $subject, $body, $headers, $sender) ){
        echo("<p>Message successfully sent!</p>");
    } else {
        echo("<p>Message delivery failed...</p>");
    }
}
?>

和我在cPanel中使用的管道命令:

usr/local/bin/php -q /public_html/[mywebsite]/email/intercept.php

当我向适当的地址发送电子邮件时,它会处理intercept.php脚本,但它也会返回一个反弹错误。

有什么想法吗?

3 个答案:

答案 0 :(得分:4)

如果将电子邮件传递给php脚本,则不能在脚本中使用“ECHO”或其他输出命令。每个输出命令都会出错。同时删除“?&gt;”从文件的末尾。此标记之后的每个字符都会生成输出标题并导致错误。

答案 1 :(得分:0)

我将其写入文件而不是echo语句。确保正确设置了目录中的写权限。

答案 2 :(得分:0)

你可以随时提出:

return NULL;

在PHP文件的末尾停止任何将停止脚本弹跳的返回消息。

相关问题