Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proper newline in emails? LF or CRLF?

Tags:

email

newline

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

like image 565
Vilx- Avatar asked Jul 21 '11 23:07

Vilx-


1 Answers

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.

like image 53
user3538058 Avatar answered Nov 02 '22 04:11

user3538058