PHP HTTP 500错误来自mail(),因为消息正文包含当前主机


PHP HTTP 500 error from mail() because message body contains the current host?

给出如下设置:

<?php
$to = "myemail@gmail.com";
$subject = "This is a test";
$body = "Login here: ";
?>

单独启用以下测试,这些可以工作:

<?php
mail($to, $subject, $body);
$bodytest = $body . "http://example.com"; 
mail($to, $subject, $bodytest);
$bodytest = $body . "http://CURRENTHOST.co"; // bad extension 
mail($to, $subject, $bodytest);
$bodytest = $body . "http:/currenthost.com"; // bad protocol
mail($to, $subject, $bodytest);
$bodytest = $body . "http:://currenthost.com"; // bad protocol
mail($to, $subject, $bodytest);
?>

单独启用以下测试,这些测试都会产生HTTP 500内部服务器错误:

<?php
$bodytest = $body . "http://currenthost.com"; // good root domain
mail($to, $subject, $bodytest);
$bodytest = $body . "http://www.currenthost.com"; // good subdomain
mail($to, $subject, $bodytest);
$bodytest = $body . "http://nonexistentsubdomain.currenthost.com"; // non-existent subdomain
mail($to, $subject, $bodytest);
?>

所以底层系统中在调用mail()时执行的某些东西在正文包含当前主机的有效文本url时终止。

搜索网页会得到一千个与mail()相关的无关的PHP HTTP 500错误,但对包含URL的正文没有任何影响。

所以我决定把这个问题贴在这里。

HTTP服务器是Apache 2.2在FreeBSD上运行。

我已经查看了Apache日志,但是没有任何提示错误。

我已经确定内部服务器故障的原因是mail()失败。我没有找到消息正文中url导致失败的绝对核心原因。

mail()失败,因为sendmail的响应码不是0 (EX_OK),而是69 (EX_UNAVAILABLE)。顺便说一句……在今天之前我从未调查过<sysexits.h>…一些新的东西!

以下是我使用的测试。
它们以:

开头
<?php
$messagebody = "Hopefuly this works.'r'nI am trying to see if this will send using'r'nthe command line through PHP'r'nLogin here: ";
$goodurl = "http://www.mywebsite.com";
?>

现在是第一次传递,没有url:

<?php
file_put_contents("testmail.txt", $messagebody );
$command = "/usr/sbin/sendmail -v -t -i myemail@gmail.com < testmail.txt";
$lastline = exec($command, $output, $returnval);
echo "Command: $command'n'n";
echo "Last line: 'n$lastline'n'n";
echo "Return val: " . $returnval. "'n'n";
echo "All lines: 'n" . var_export($output, true). "'n'n";
?>

和第二个传递,URL:

<?php
file_put_contents("testmail.txt", $messagebody . $goodurl );
$command = "/usr/sbin/sendmail -v -t -i myemail@gmail.com < testmail.txt";
$lastline = exec($command, $output, $returnval);
echo "Command: $command'n'n";
echo "Last line: 'n$lastline'n'n";
echo "Return val: " . $returnval. "'n'n";
echo "All lines: 'n" . var_export($output, true). "'n'n";
?>

对相关输出的检查,包括第一次和第二次传递的详细行(使用占位符):

传递没有url:

Return val: 0
All lines: 
array( ...
20 => '>>> DATA',
21 => '250 Recipient <myemail@gmail.com> OK',
22 => '354 Start mail input; end with <CRLF>.<CRLF>',
23 => '>>> .',
24 => '250 Ok: queued as C19C41AEE4E6',
25 => 'myemail@gmail.com... Sent (Ok: queued as C19C41AEE4E6)',
26 => 'Closing connection to barracuda.hoster.com.',
27 => '>>> QUIT',
...
)

输入url失败:

Return val: 69
All lines: 
array (
20 => '>>> DATA',
21 => '250 Recipient <myemail@gmail.com> OK',
22 => '354 Start mail input; end with <CRLF>.<CRLF>',
23 => '>>> .',
24 => '554 rejected due to spam content',
25 => '/web/mywebsite.com/dead.letter... Saved message in /web/mywebsite.com/dead.letter',
26 => 'Closing connection to barracuda.hoster.com.',
27 => '>>> QUIT',
...
)

我不熟悉垃圾邮件过滤系统。此故障发生在Barracuda垃圾邮件防火墙或谷歌的消息过滤器中。

没有进一步的了解,我称它为一天(实际上是两天),回到电子邮件正文的来源并删除url。任何有见地的想法都将非常感谢!

以下是我发现的与此相关的其他一些注意事项:

https://productforums.google.com/forum/!主题/gmail/PTpkPX9EFAU

https://support.google.com/mail/answer/1366858?hl=en& ctx = mail& authuser = 2,扩大= 5