【问题标题】:Whats wrong with my multipart/alternative Email?我的多部分/替代电子邮件有什么问题?
【发布时间】:2014-09-27 04:22:59
【问题描述】:

我正在尝试建立自己的电子邮件发送类,但我的 MIME 似乎有问题。 如果有人能找到错误或告诉我有关工作的 MIME 验证器的信息,我将不胜感激。

提前致谢 京东

To: me@mydomain.com
Subject: Test Alternate
X-PHP-Originating-Script: 1000:SendMail.class.php
MIME-Version: 1.0
From: me@mydomain.com
Content-Type: multipart/mixed;
 boundary="MultipartMail53dfa8ade817e"
Message-Id: <20140804153717.EA93E160195@myDevice>
Date: Mon,  4 Aug 2014 17:37:17 +0200 (CEST)
X-RCPT-TO: <me@mydomain.com>
Status:  
X-UIDL: 706801872
X-IMail-ThreadID: c9b40003d631c851

--MultipartMail53dfa8ade817e
Content-Type: multipart/alternative;
 boundary="Alternative53dfa8ade8378"


--Alternative53dfa8ade8378
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Some Text content


--Alternative53dfa8ade8378
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit


Das ist Text
-- 

Text

*Some more Text*
Text



--Alternative53dfa8ade8378--

--MultipartMail53dfa8ade817e--

【问题讨论】:

  • “我的 MIME 似乎有问题”——是什么让你这么认为?
  • 我正在将邮件发送到我的电子邮件地址,并使用 Thunderbird 进行检查,但无法在 html 和纯文本之间切换。我已经尝试从 Thunderbird 本身发送具有相同内容的它,它正在工作,但我看不出有任何区别......所以我认为格式有问题,我找不到它

标签: email mime


【解决方案1】:

您的电子邮件有几处“错误”:

首先,您的标头中有一个非标头:

To: me@mydomain.com
*Test Alternate*
X-PHP-Originating-Script: 1000:SendMail.class.php

(*'s around the broken bit)

其次,(可能是您使用 Thunderbird 的主要问题)是您的 multipart/alternative 的子部分顺序错误。 multipart/alternative 应该工作的方式是最后一部分应该是最接近消息的原始作者打算让您看到的形式(IOW 他/她在他们的所见即所得编辑器中看到的内容)。

TL;DR

将text/html 部分放在最后,将text/plain 部分放在multipart/alternative 的最前面。

【讨论】:

  • 谢谢,切换 text/plain 和 text/html 成功了,非常感谢,我不认为这些定位会相关... Test Alternate 似乎是复制粘贴错误,那就是主题:行 ;-)
  • 从w3.org/Protocols/rfc1341/7_2_Multipart.html(参见7.2.3 Multipart/alternative 子类型)你得到:... In particular, each of the parts is an "alternative" version of the same information. User agents should recognize that the content of the various parts are interchangeable. The user agent should either choose the "best" type based on the user's environment and preferences, or offer the user the available alternatives. In general, choosing the best type means displaying only the LAST part that can be displayed. 这使得顺序很重要。
猜你喜欢
  • 2012-03-05
  • 1970-01-01
  • 2014-06-21
  • 1970-01-01
  • 2014-01-23
  • 2011-05-06
  • 2018-07-11
  • 2013-07-31
  • 1970-01-01
相关资源
最近更新 更多