我正在尝试使用内置的 PHP 邮件功能来发送包含我的消息的 html 和纯文本版本的多部分消息。我一直在玩不同的编码类型,但是我一直遇到问题。最初我设置Content-Transfer-Encoding
为Binary
但是,这导致每 78 个字符放置一个感叹号。我也尝试过base64
,但我相信 base64 对我正在做的事情来说太过分了。
我所做的只是发送基本的 HTML,没有编码的图像、文件或附件。我更喜欢一种仍然允许源代码可读的编码方法。
我听说这Quoted-Printable
就是我正在寻找的东西,但是,当我尝试使用该编码类型发送消息时,结果看起来真的很奇怪。"
我注意到消息源代码中散布着一堆符号。
这是我正在使用的代码:
$to = "to@test.com";
$subject = "test subject";
$boundary = uniqid('np');
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: from-address@test.com\r\n";
$headers .= "Reply-To: reply-address@test.com\r\n";
$headers .= "Return-Path: return-path@test.com\r\n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
$message = "This is a MIME encoded message.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-Type: text/plain; charset=UTF-8\r\n";
$message .= "Content-Transfer-Encoding: Quoted-Printable\r\n";
$message .= $plainTextMessage;
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-Type: text/html; charset=UTF-8\r\n";
$message .= "Content-Transfer-Encoding: Quoted-Printable\r\n";
$message .= $HTMLmessage;
$message .= "\r\n\r\n--" . $boundary . "--";
$ok = mail($to,$subject,$message,$headers);
我到底做错了什么?