Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send email with line breaks using mail() in php

Tags:

php

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

like image 325
Prady Avatar asked Sep 24 '10 11:09

Prady


2 Answers

It's \r\n, as in backslash not forward slash.

Also you can try it like this:

$message = "

Hi!

This is one line.

And this is another.



Bye!
";
like image 187
Gal Avatar answered Sep 18 '22 21:09

Gal


you should set the content type of the mail (read: tell php you're sending a html e-mail) http://php.net/manual/en/function.mail.php

it's all explained in Example #5 Sending HTML email.

like image 45
In81Vad0 Avatar answered Sep 17 '22 21:09

In81Vad0