Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

newline not working in PHP mail

Tags:

php

email

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.

like image 915
ChuckO Avatar asked Jun 18 '10 22:06

ChuckO


People also ask

How do I insert a line break into the body of an email in PHP?

`"<br>"`;

How do you insert a new line in an email?

%0d%0a is the new line symbol of the email body in a mailto link.

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

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

like image 173
Oren Avatar answered Sep 28 '22 01:09

Oren