栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

从PHP发送HTML电子邮件

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

从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 <foo@gmail.com>";$from = "Me.com <me@me.com>";$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;

-凯文



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/433184.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号