电子邮件中正确的换行符是什么? LF 还是 CRLF?
最近,一些客户抱怨他们收到乱码电子邮件。显示 MIME 标头和 Base64 编码数据等。这些内容应该由邮件客户端解码。
经过调查,我发现一些邮件客户端(例如 gmx.de webmail)在每隔一行之后插入一个空行,因此确实搞乱了一切。
凭直觉,我更改了邮件发送代码,将所有 CRLF 替换为 LF。你瞧,邮件完整抵达。
现在,这很奇怪,因为 RFC 5322 明确指出
2.3。正文
消息正文只是几行 US-ASCII 字符。这 对本体只有两个限制:
o CR 和 LF 只能作为 CRLF 一起出现;他们一定不能出现 在体内独立。
嗯?网络邮件不好?还是我哪里做错了?其他网络邮件(如 gmail)对此没有任何问题,而且实际上似乎大多数人都没有问题(因为投诉很少)。
请注意 - 我正在 Linux 机器上通过 PHP 的 mail()
函数发送电子邮件。底层邮件软件好像是qmail,但我不确定。
看来qmail 在类似条件下不喜欢 CRLF。这可能是问题所在吗?不是已经修复了吗(该页面已经四年没有更新了)?
Recently some customers complained that they were getting garbled emails. MIME headers were showing, and base64 encoded data, etc. Stuff that should have been decoded by their mail clients.
After investigating I found that some mail clients (gmx.de webmail to name one) inserted a blank line after every other line, thus indeed messing everything up.
Following a hunch, I changed my mail sending code to replace all CRLF with just LF. And lo and behold - the mail arrived whole.
Now, this is weird, because RFC 5322 explicitly states that
2.3. Body
The body of a message is simply lines of US-ASCII characters. The
only two limitations on the body are as follows:o CR and LF MUST only occur together as CRLF; they MUST NOT appear
independently in the body.
Huh? Bad webmail? Or did I go wrong somewhere? Other webmails (like gmail) have no problems with this, and indeed it seems that majority of people have no problems (since complaints are few).
Just to note - I'm sending email through PHP's mail()
function on a Linux box. The underlying mail software seems to be qmail, but I'm not sure.
It seems that qmail doesn't like CRLF under similar conditions. Could this be the problem? Isn't it fixed already (that page hasn't updated in 4 years)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://www.php.net/manual/en/function.mail.php 状态
http://www.php.net/manual/en/function.mail.php states