Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

html to email

add html to email

want to add
<br>

\n
\t
&nbsp;

will the output show <br> instead of linebreak
with different email clients
<?php
 
$Name = "Da Duder"; //senders name
$email = "email@adress.com"; //senders e-mail adress
$recipient = "PersonWhoGetsIt@emailadress.com"; //recipient
$mail_body = "The text for the mail..."; //mail body
$subject = "Subject for reviever"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields
 
mail($recipient, $subject, $mail_body, $header); //mail command :)
?>

Open in new window

Avatar of Greg Alexander
Greg Alexander
Flag of United States of America image

That will show up as a return in the email, the \r\n will work for Linux or Windows
Avatar of rgb192

ASKER

when i add

<br>

\n
\t
&nbsp;

to the mail body

sometimes is not a line break

is there code to allow html in mail()
Add some additional headers
<?php
 
$Name = "Da Duder"; //senders name
$email = "email@adress.com"; //senders e-mail adress
$recipient = "PersonWhoGetsIt@emailadress.com"; //recipient
$mail_body = "The text for the mail...<br><b>with html</b>"; //mail body
$subject = "Subject for reviever"; //subject
 
$header = "From: \"".$from_name."\" <".$from_email.">\n"; 
$header .= "To: \"".$to_name."\" <".$to_email.">\n"; 
$header .= "Return-Path: <".$from_email.">\n"; 
$header .= "MIME-Version: 1.0\n"; 
$header .= "Content-Type: text/html; charset=ISO-8859-1\n"; 

mail($recipient, $subject, $mail_body, $header); //mail command :)
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Greg Alexander
Greg Alexander
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Loganathan Natarajan
if you add additional headers, it will include the HTML display.

$header = "From: \"".$from_name."\" <".$from_email.">\n";
$header .= "To: \"".$to_name."\" <".$to_email.">\n";
$header .= "Return-Path: <".$from_email.">\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: text/html; charset=ISO-8859-1\n";
That's exactly the solution I made!?
Avatar of rgb192

ASKER

will this allow both
<br>

and
\n

in the
$mail_body
If you use html headers, it will transfer as html only, so the answer is no, it will not allow both.
Avatar of rgb192

ASKER

thanks