我的多部分电子邮件脚本可以很好地发送 HTML 消息,但纯文本替代方案不起作用,可能出了什么问题?

发布于 2024-08-28 21:01:36 字数 1916 浏览 3 评论 0原文

我设置了一个脚本来发送多部分电子邮件;纯文本和 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与君绝 2024-09-04 21:01:36

问题是我正在使用的定界符语法中存在空格。上面的例子中没有体现。

@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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文