PHP 邮件功能失败,并显示“邮件的行数太长,无法传输”

PHP mail function fails with "message has lines too long for transport"

提问人:unstuck 提问时间:8/4/2022 更新时间:8/28/2022 访问量:1472

问:

我正在使用 PHP 7.4.30,我对 PHP 完全陌生。

$subject ="My subject";

$message = '<html><body>';
$message .= '<div style="text-align: center; width: 100%; background-color: #fff;">';
$message .= '<div class="info">&nbsp;</div>';
$message .= '<table style="text-align: justify; margin: auto; background-color: #ebebeb; border: 1px solid #e7e7e7; width: 600px;" cellspacing="0" cellpadding="0" bgcolor="#ebebeb" align="center">';
$message .= '<tbody>';
$message .= '<tr style="line-height: 0px;">';
$message .= '<td style="line-height: 0';


$from = "My website<[email protected]>";
$replyto = "[email protected]"; 

$headers = 'Content-Type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$headers .= 'Reply-To: '. $replyto . "\r\n";
$headers .= 'Bcc: [email protected]'; 

$message = str_replace("\n.", "\n..", $message);
mail($to, $subject, $message, $headers);

查看服务器的投放跟踪,我看到错误消息:

"message has lines too long for transport"

谁能帮忙?

PHP的

评论

2赞 CBroe 8/4/2022
这回答了你的问题吗?501 语法错误 - 行太长
0赞 unstuck 8/4/2022
谢谢,问题似乎很相似,但我的PHP技能是基本的。我想我必须在每行末尾添加“\n”?
1赞 CBroe 8/4/2022
尝试使用您的值,就像那里建议的那样。chunk_split$message$message = chnuk_split($message, 998);
0赞 unstuck 8/4/2022
成功了!!非常感谢!Chaged chnuk 到 chunk

答:

2赞 salar zaidi 8/28/2022 #1

我最近遇到了这个问题。解决此问题的一个简单方法是替换此行

$message = str_replace("\n.", "\n..", $message);

$message = wordwrap($message, 70,"\r\n");