电子邮件中正确的换行符是什么? LF还是CRLF? [英] What is the proper newline in emails? LF or CRLF?

查看:772
本文介绍了电子邮件中正确的换行符是什么? LF还是CRLF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,一些客户抱怨他们收到乱码的电子邮件.正在显示MIME标头和base64编码的数据等.应由其邮件客户端解码的内容.

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.

经过调查,我发现某些邮件客户端(gmx.de网络邮件仅举几例)每隔一行插入一个空白行,因此确实弄乱了所有内容.

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.

直觉之后,我更改了邮件发送代码,将所有CRLF替换为LF.瞧,这封邮件全都收到了.

Following a hunch, I changed my mail sending code to replace all CRLF with just LF. And lo and behold - the mail arrived whole.

现在,这很奇怪,因为 RFC 5322 明确声明了

Now, this is weird, because RFC 5322 explicitly states that

2.3.身体

2.3. Body

消息的正文只是US-ASCII字符的行.这 对身体的两个限制如下:

The body of a message is simply lines of US-ASCII characters. The only two limitations on the body are as follows:

o CR和LF只能作为CRLF一起出现;他们一定不能出现

o CR and LF MUST only occur together as CRLF; they MUST NOT appear independently in the body.

嗯?网络邮件错误?还是我在某个地方出错了?其他网络邮件(例如gmail)对此没有任何问题,实际上似乎大多数人都没有问题(因为投诉很少).

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).

仅需注意-我正在Linux机器上通过PHP的mail()函数发送电子邮件.基本的邮件软件似乎是qmail,但是我不确定.

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.

qmail在类似条件下不喜欢CRLF .这可能是问题吗?是否已经修复(该页面已经4年没有更新了)?

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)?

推荐答案

http: //www.php.net/manual/zh-CN/function.mail.php 声明

注意:

如果未收到消息,请尝试仅使用LF(\ n).一些Unix邮件传输代理 (最值得注意的是qmail)自动将CR替换为CRLF(如果 使用CRLF).这应该是不得已的方法,因为它不符合RFC 2822.

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.

这篇关于电子邮件中正确的换行符是什么? LF还是CRLF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆