Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which line break in php mail header, \r\n or \n?

Tags:

php

email

header

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

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

vs

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

which one is correct?

Sometimes I've had cases where \r\n is used and part of the header is interpreted by some email clients as mail text (losing these header information) - is this because \r\n is wrong?

like image 828
Sam Avatar asked Dec 11 '10 07:12

Sam


People also ask

How do you add a line in an email body?

1. %0d%0a is the new line symbol of the email body in a mailto link. Please enter the %0d%0a symbol next to the original body text in the Subject box, and then type the new line content after the symbol.

What does N N mean in PHP?

\n is the newline or linefeed, other side \r is the carriage return.

How do I add a line in HTML email?

In the most basic way you can Just press Ctrl + Enter when typing out the email, e.g. If you are needing something more complex, then you can Generate the email using a hidden HtmlText Box. If you are comfortable with HTML. You can then add a <br/> tag to allow a new line.


1 Answers

The CRLF \r\n, 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 \r\n 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.

like image 57
Russell Dias Avatar answered Oct 08 '22 12:10

Russell Dias