我的多部分电子邮件脚本可以很好地发送 HTML 消息,但纯文本替代方案不起作用,可能出了什么问题?
我设置了一个脚本来发送多部分电子邮件;纯文本和 html 消息。 HTML 消息工作得很好,但是当我使用只处理纯文本的电子邮件客户端时,纯文本消息不会呈现,我得到以下信息:
--
此消息由我自动生成
http://www.somewebsite.com/
$html_msg = $message_details;
$plain_text_msg = strip_tags($message_details);
$headers = <<<HEADERS
From: Me <[email protected]>
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="==PHP-alt$mime_boundary"
HEADERS;
// Use our boundary string to create plain text and HTML versions
$message = <<<MESSAGE
--==PHP-alt$mime_boundary
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
$plain_text_msg
--
This message was generated automatically by Me
http://www.somewebsite.com/
If you did not request this message, please notify [email protected]
--==PHP-alt$mime_boundary
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<html>
<body>
$html_msg
<p>
--<br />
This message was generated automatically as a demonstration on
<a href="http://www.somewebsite.com/">Me</a>
</p>
<p>
If you did not request this message, please notify
<a href="mailto:[email protected]">[email protected]</a>
</p>
</body>
</html>
--==PHP-alt$mime_boundary--
MESSAGE;
I have a script set up to send out multipart emails; plain text and html messages. The HTML messages work just fine, but when I used an email client that only does plain text the plaint text message does not render and I get the following:
--
This message was generated automatically by Me
http://www.somewebsite.com/
$html_msg = $message_details;
$plain_text_msg = strip_tags($message_details);
$headers = <<<HEADERS
From: Me <[email protected]>
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="==PHP-alt$mime_boundary"
HEADERS;
// Use our boundary string to create plain text and HTML versions
$message = <<<MESSAGE
--==PHP-alt$mime_boundary
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
$plain_text_msg
--
This message was generated automatically by Me
http://www.somewebsite.com/
If you did not request this message, please notify [email protected]
--==PHP-alt$mime_boundary
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<html>
<body>
$html_msg
<p>
--<br />
This message was generated automatically as a demonstration on
<a href="http://www.somewebsite.com/">Me</a>
</p>
<p>
If you did not request this message, please notify
<a href="mailto:[email protected]">[email protected]</a>
</p>
</body>
</html>
--==PHP-alt$mime_boundary--
MESSAGE;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是我正在使用的定界符语法中存在空格。上面的例子中没有体现。
@qor72 感谢您的意见。
The issue was white space in the heredoc syntax I'm using. It is not represented in the above example.
@qor72 thank you for your input.