Newline does not work in PHP mail

I use 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 a message is received, it does not start a new line at "\ r \ n", but simply prints them as part of the message.

I only tried it in Thunderbird 3 and not other clients.

+44
php email
Jun 18 '10 at 22:13
source share
3 answers

Try changing ' to " - php interprets the string inside single quotes as literals, while with quotes ( " ) it extends \r\n to whatever you want.

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

+95
Jun 18 '10 at 22:14
source share

Not an answer to a question, but it might help someone.

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

And use <PRE></PRE> or CSS for pre-formatted text, moving \ n to newlines.

 $headerFields = array( "From: who@are.you", "MIME-Version: 1.0", "Content-Type: text/html;charset=utf-8" ); mail($to, $subj, $msg, implode("\r\n", $headerFields)); 
+2
Dec 22 '15 at 9:36
source share
 <?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); ?> 
0
Nov 28 '14 at 20:16
source share



All Articles