从PHP发送HTML电子邮件

从PHP发送HTML电子邮件,第1张

从PHP发送HTML电子邮件

原来关键是编码类型。代替:

Content-Type: text/plain; charset="iso-8859-1"

我需要使用:

Content-Type: text/plain; charset=us-ascii

它可能取决于您如何在自己的文本编辑器中保存PHP文件的细节。我没有研究它,但是PHP中的 iconv
函数可能也给我带来了一些乐趣。所以我认为这部分确实很敏感。

这是一个更好的示例代码片段,以端到端的方式展示了整个过程

$notice_text = "This is a multi-part message in MIME format.";$plain_text = "This is a plain text email.rnIt is very cool.";$html_text = "<html><body>This is an <b style='color:purple'>HTML</b> text email.rnIt is very cool.</body></html>";$semi_rand = md5(time());$mime_boundary = "==MULTIPART_BOUNDARY_$semi_rand";$mime_boundary_header = chr(34) . $mime_boundary . chr(34);$to = "Me <[email protected]>";$from = "Me.com <[email protected]>";$subject = "My Email";$body = "$notice_text--$mime_boundaryContent-Type: text/plain; charset=us-asciiContent-Transfer-Encoding: 7bit$plain_text--$mime_boundaryContent-Type: text/html; charset=us-asciiContent-Transfer-Encoding: 7bit$html_text--$mime_boundary--";if (@mail($to, $subject, $body,    "From: " . $from . "n" .    "MIME-Version: 1.0n" .    "Content-Type: multipart/alternative;n" .    "     boundary=" . $mime_boundary_header))    echo "Email sent successfully.";else    echo "Email NOT sent successfully!";exit;


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5641068.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存