Skip to content
Advertisement

Which line break in php mail header, rn or n?

I’ve seen a lot of examples using the php mail function. Some of them use rn as line break for the header, some use n.

$headers = "From: Just Men"; 
$headers .= "Reply-To:  Just me <$email>n"; 

vs

$headers = "From: Just Mern";
$headers .= "Reply-To:  Just me <$email>rn";

which one is correct?

Sometimes I’ve had cases where rn is used and part of the header is interpreted by some email clients as mail text (losing these header information) – is this because rn is wrong?

Advertisement

Answer

The CRLF rn, should be used according to the php documentation. Also, to conform to the RFC 2822 spec lines must be delimited by the carriage return character, CR r immediately followed by the line feed, LF n.

Since rn is native to Windows platforms and n to Unix, you can use the PHP_EOL­Docs constant on Windows, which is the appropriate new line character for the platform the script is currently running on.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement