我已经升级到php 8.1,现在用mail()发送的电子邮件在正文开始时带着以下内容到达,在此之前它没有:
--PHP-alt-4de4a7c8434ad5b8f6adb6e50c35b0da
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit我在标题信息中看到的唯一不同之处是,每个标头行现在都有一个空格(下面第2-5行):
X-PHP-Script: www.example.com/file.php for 0.0.0.0
From: Name <name@example.com>
Reply-To: name@example.com
Content-Type: multipart/alternative; boundary="PHP-alt-4de4a7c8434ad5b8f6adb6e50c35b0da"
MIME-Version: 1.0
Message-Id: <E1oJ4gz-006Rkx-8b@whub53.webhostinghub.com>有什么原因吗?
注意:我在正文中使用“--”作为发送带有纯文本回退的HTML消息的方法。这是一种在不同地方发现的演示方法。
我的代码:
$headers[] = $from;
$headers[] = "Reply-To: " . $fromemail;
$headers[] = "Content-Type: multipart/alternative; boundary=\"PHP-alt-" . $random_hash . "\"";
$headers[] = "MIME-Version: 1.0";
// plain text version
$body[] = "--PHP-alt-$random_hash";
$body[] = "Content-Type: text/plain; charset=\"utf-8\"";
$body[] = "Content-Transfer-Encoding: 8bit";
$body[] = "";
$body[] ="$message";
// html version
$body[] = "--PHP-alt-$random_hash";
$body[] = "Content-Type: text/html; charset=\"utf-8\"";
$body[] = "Content-Transfer-Encoding: 8bit";
$body[] = "";
$body[] = "<html><head>";
$body[] = "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />";
$body[] = "<title>$subject</title>";
$body[] = "</head>";
$body[] = "<body>";
$body[] = $message;
$body[] = "</body></html>";
$body[] = "--PHP-alt-$random_hash--";
$success = mail($email, $subject, implode("\r\n", $body), implode("\r\n", $headers)); 发布于 2022-08-08 18:15:43
Phpv8.1和v7.4之间行为的变化是,使用PHP_EOL导致无法识别替代邮件视图的--PHP-alt-标记。
将其更改为"\r\n“解决了该问题。我以为我一开始就得到了所有这些信息,但是调用fn中还有一个PHP_EOL的实例。
https://stackoverflow.com/questions/73245569
复制相似问题