开发者

What is the proper newline in emails? LF or 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 qma开发者_如何学Cil 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/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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜