PHP new line break in emails PHP new line break in emails php php

PHP new line break in emails


Try \r\n in place of \n

The difference between \n and \r\n

It should be noted that this is applicable to line returns in emails. For other scenarios, please refer to rokjarc's answer.


I know this is an old question but anyway it might help someone.

I tend to use PHP_EOL for this purposes (due to cross-platform compatibility).

echo "line 1".PHP_EOL."line 2".PHP_EOL;

If you're planning to show the result in a browser then you have to use "<br>".

EDIT: since your exact question is about emails, things are a bit different.For pure text emails see Brendan Bullen's accepted answer. For HTML emailsyou simply use HTML formatting.


Are you building this string using single or double quotes? \r and \n only work with double quotes, as well as embedded variables. For example:

$foo = 'bar';echo 'Hello \n $foo!';

will output:

Hello \n $foo!

But:

$foo = 'bar';echo "Hello \n $foo!";

will output:

Hellobar!