我正在尝试发送一封电子邮件(整个电子邮件都在标题中)。实际上,电子邮件正在发送。但当它到达目的地时,内容已被删除。如果我从不同的服务器发送完全相同的电子邮件,由相同的代码构建,那么一切都很好。
当我用nl2br(htmlspecialchars($headers, ENT_QUOTES))
打印出来时,我得到的是:
From: kittsil@example.com
Reply-to: kittsil@example.com
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="cccf6094979eaede770a2a2e88fc83e9"
Content-Transfer-Encoding: 7bit
This is a MIME encoded message.
--cccf6094979eaede770a2a2e88fc83e9
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
You are not being awesome....
--cccf6094979eaede770a2a2e88fc83e9--
当电子邮件发送时,正文是空的,当我在Gmail的"显示原始邮件"中看到它时,它看起来是一样的,但内容不在那里。
我正在使用postfix和OpenDKIM,但我禁用了它们中的每一个,甚至切换回sendmail,这些电子邮件都没有正文。我为这件事伤透了脑筋。
邮件正文中缺少空行。
引用自RFC:
每个部分从封装边界开始,然后包含一个主体部分,该主体部分由标题区域、一个空行和一个主体区域组成。
(强调矿)
添加适当的空行,它就起作用了:
标题:
From: kittsil@example.com
Reply-to: kittsil@example.com
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="cccf6094979eaede770a2a2e88fc83e9"
Content-Transfer-Encoding: 7bit
正文:
This is a MIME encoded message.
--cccf6094979eaede770a2a2e88fc83e9
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
You are not being awesome....
--cccf6094979eaede770a2a2e88fc83e9--