Send email with line breaks using mail() in php

Viewed 59769

I am trying to send email using mail() in php. I need the message to be formatted or at least allow line breaks.

$mail = mail(WEBMASTER_EMAIL, $subject, $message,
 "From: ".$name." <".$email.">/r/n"
 ."Reply-To: ".$email."/r/n"    
 ."X-Mailer: PHP/" . phpversion());

Do i need to provide "< br/>" tags in the $message or /r/n. Tried both but they came in as
or /r/n and not line breaks

Thanks Prady

5 Answers

To format message body you should use \n, as follow:

$message = "Hi!
\nThis is one line.
\nAnd this is another.
\nBye!";

This is formatting your message body.

It's the solution I got after waisting too many time and It's working perfectly.

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>".

Related