多部分/混合电子邮件。配有空身。怎么了?

时间:2009-12-10 11:03:09

标签: php email content-type multipart

发送电子邮件:

From: <...>
X-Mailer: SnowBoss
Reply-To: <...>
X-Priority: 3 (Normal)
Message-ID: <248.20091210135259@snowman2010.com>
To: <...>
Subject: =?UTF-8?B?0JzQntCZIFNVQkpFQ1Q=?=
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="----------A4D921C2D10D7DB"

This is a multi-part message in MIME format.

----------A4D921C2D10D7DB
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

MY TEXT
----------A4D921C2D10D7DB
Content-Type: text/html;
charset=utf-8
Content-Transfer-Encoding: 8bit

<html><b>BOLD</b></html>
----------A4D921C2D10D7DB
.

<250 Data received OK. //server response

它带有空体。这仅适用于multipart/mixed内容(已尝试multipart/alternative - 相同的故事)

3 个答案:

答案 0 :(得分:5)

正如Tomasz所提到的那样,使用边界的线,你必须在边界分离器的开头有两个连字符。请检查以下内容:

MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="frontier"

This is a message with multiple parts in MIME format.
--frontier
Content-Type: text/plain

This is the body of the message.
--frontier
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64

PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgPHA+VGhpcyBpcyB0aGUg
Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg==
--frontier--

另请注意,在最后一个边界处,您必须再放两个连字符来表示它是结束。

取自维基百科的示例,请参阅here

答案 1 :(得分:3)

我猜你可能有错误的边界。

边界看起来应该是

Content-Type: multipart/alternative; boundary="--------A4D921C2D10D7DB"

含义 - 包含两个' - '字符。查看任何电子邮件的来源。

邮件结束边界 - 另一方面 - 应该看起来像

----------A4D921C2D10D7DB--

(再次,请参阅任何邮件的来源。或者阅读RFC,当然:))。

我鼓励您使用exisitng邮件程序类,例如Swift MailerPHPMailer。为什么重新发明轮子?

答案 2 :(得分:1)

我猜你的意思是“这是MIME格式的多部分邮件”。作为粘贴在内容片段中的正文。 当内容类型设置为mimepart / alternatie或mimepart / mixed时,它取决于电子邮件客户端是否呈现正文。 几乎所有客户都可以看到身体部位。