电子邮件中正确的换行符是什么? LF 还是 CRLF?

发布于 2024-11-25 16:34:08 字数 746 浏览 0 评论 0原文

最近,一些客户抱怨他们收到乱码电子邮件。显示 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 技术交流群。

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

发布评论

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

评论(1

水波映月 2024-12-02 16:34:08

http://www.php.net/manual/en/function.mail.php 状态

注意:

如果未收到消息,请尝试仅使用 LF (\n)。一些 Unix 邮件传输代理
(最显着的是 qmail)自动用 CRLF 替换 LF(这会导致 CR 加倍,如果
使用 CRLF)。这应该是最后的手段,因为它不符合 RFC 2822。

http://www.php.net/manual/en/function.mail.php states

Note:

If messages are not received, try using a LF (\n) only. Some Unix mail transfer agents
(most notably qmail) replace LF by CRLF automatically (which leads to doubling CR if
CRLF is used). This should be a last resort, as it does not comply with RFC 2822.

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