Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add line breaks in mail function php

Tags:

php

I'd like to send email using mail function. Want to add line breaks as follows.

$msg = 'aaaaa'.'\r\n'.'bbbbbb'.'\r\n';
$headers .= "Content-Type: text/plain; charset=\"utf-8\"\r\n";
$to = '[email protected]';
mail($to,'Subject',$msg,$headers);

But not working.

How can I send email as follows.

aaaaa

bbbbbb

like image 988
Jin Avatar asked Aug 11 '26 20:08

Jin


2 Answers

New line is "\n", not '\n' (double quotes instead of single-quotes).

$msg = 'aaaaa'."\n".'bbbbbb'."\n";

Explanation is here:

http://php.net/manual/en/language.types.string.php#language.types.string.syntax.double

If the string is enclosed in double-quotes ("), PHP will interpret more escape sequences for special characters

like image 66
nospor Avatar answered Aug 14 '26 10:08

nospor


To add line break you need to add "\n", not '\n'


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!