PHP mail() docs say that I should only use LF in the body, but RFC 5322 says otherwise.

759 Views Asked by At

PHP manual (http://php.net/manual/en/function.mail.php) says:

Each line should be separated with a LF (\n). Lines should not be larger than 70 characters.

But actual RFC 5322 gives totallty different information:

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. o Lines of characters in the body MUST be limited to 998 characters, and SHOULD be limited to 78 characters, excluding the CRLF.

So - RFC says that only \r\n should be used. I don't understand - how does php mail() work in the background?

2

There are 2 best solutions below

1
On BEST ANSWER

how does php mail() work in the background?

Exactly as you might expect from the cionfiguration. By default its simply a wrapper around the sendmail binary on most systems and a very simple MUA where an SMTP host is specified. While the former uses a LF as a line ending in its input, the latter requires a CRLF for its output - since line endings vary by OS, PHP provides a unified line ending for mail (LF)

0
On

Obviously PHP mail() must be converting \n to \r\n in the background.

This is similar to Perl's practice of using \n to represent the "logical" newline and then translating them internally depending on the OS. Since PHP was partially inspired by Perl, it's not really a surprise that a similar mechanism exists in PHP.