为什么电子邮件在正文/中显示 mime 边界
我正在尝试通过 PHP mail() 发送带有附件的电子邮件。
附件传输正常,正文内容也在那里,但我还看到了 mime 边界和内容类型,而不是电子邮件是 HTML
--==Multipart_Boundary_x9e92752e972e274a182cc4cafd83c674xContent-Type: text/html; charset="iso-8859-1"Content-Transfer-Encoding: 7bit
<p>
Body content</p>
<p> <snip>
代码如下所示:
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
$message = "--{$mime_boundary}Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n" . $bodyText . "\r\n";
$message .= "--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
then the attachment routine
我已经尝试了许多代码变体,但没有成功。毫无疑问,这将是一些我看不到的微不足道的事情。
提前致谢
I am trying to send an email via PHP mail() with attachments.
The attachments come through OK and the content of the body is there but I also see the mime boundary and content type rather than the email being HTML
--==Multipart_Boundary_x9e92752e972e274a182cc4cafd83c674xContent-Type: text/html; charset="iso-8859-1"Content-Transfer-Encoding: 7bit
<p>
Body content</p>
<p> <snip>
The code looks like this:
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
$message = "--{$mime_boundary}Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n" . $bodyText . "\r\n";
$message .= "--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
then the attachment routine
I've tried many variations on the code without success. No doubt it will be something trivial I just can't see.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您两次忘记了正确的行结尾。
第一个
\r\n
丢失。这里你只写了
\n
而不是\r\n
。另外不要忘记,您需要在最后有一个终止 MIME 边界,并以双减号作为终止符:
You forgot the correct line endings twice.
There is the first
\r\n
missing.Here you only wrote
\n
instead of\r\n
.Also don't forget that you need a terminating MIME boundary at the very end with a closing double minus as terminator:
看起来您在边界定界符之后缺少所需的 CRLF,而且定界符也可能缩进(但一定不能缩进),尽管这可能只是这里的代码格式。看起来您只使用换行符而不是强制的 CRLF。
您应该认真考虑使用成熟的邮件库,例如 SwiftMailer 来轻松地为您组装 MIME 消息。
It looks like you're missing the required CRLF after the boundary delimiter, and also possibly that the delimiter may be indented (which it must not be), though that might just be the code formatting here. It also looks like you're using only newlines instead of the mandatory CRLFs.
You should seriously consider using a mature mailing library, like SwiftMailer to assemble MIME messages for you with ease.