newline not working in PHP mail

PhpEmail

Php Problem Overview


I'm using the following to send an email:

<php ....
$message = 'Hi '.$fname.', \r\n Your entries for the week of '
   .$weekof.' have been reviewed. \r\n Please login and View Weekly reports to see the report and comments. \r\n Thanks, \r\n'.$myname;

mail($to, $subject, $message, $from);
?>

When the message is received it does not start a new line at the "\r\n" but just prints them as part of the message.

I only tried it in Thunderbird 3, not any other clients.

Php Solutions


Solution 1 - Php

Try to change your ' to " - php interprets a string inside single quotes as literals, whereas with quotes (") it will expand the \r\n to what you want.

More information: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single

Solution 2 - Php

Not an answer to the question, but may be of help to someone.

Send a HTML message, and instead of \n, use <BR>.

And use <PRE></PRE> or CSS for preformatted text, thus translating \n to actual new lines.

$headerFields = array(
	"From: [email protected]",
	"MIME-Version: 1.0",
	"Content-Type: text/html;charset=utf-8"
	);
mail($to, $subj, $msg, implode("\r\n", $headerFields));

Solution 3 - Php

<?php ....
$message = "Hi ".$fname.", \r\n Your entries for the week of "
   .$weekof." have been reviewed. \r\n Please login and View Weekly reports to see the report and comments. \r\n Thanks, \r\n".$myname;

mail($to, $subject, $message, $from);
?>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChuckOView Question on Stackoverflow
Solution 1 - PhpOrenView Answer on Stackoverflow
Solution 2 - PhpHarijs KrūtainisView Answer on Stackoverflow
Solution 3 - PhpkayleighsdaddyView Answer on Stackoverflow