Why isn't the html of sent mails being rendered?

Go To StackoverFlow.com

1

My script send the email but it doesn't render the html tags. I'm not sure why not.

$email = $row['email'];

$mail_body = '<html>
<body>

<p>hello,'.$name.'</p>
<p>this is a testing email </p>
<hr />
<p>by server</p>
</body>
</html>';
$subject = "Better website";
$to = "$email";

$headers = "From: mailscript@hotmail.com\r\n";
$headers .= "Content-Type: text/html\r\n";

$mail_result = mail($to, $subject, $mail_body, $headers);
2012-04-04 17:19
by hamp13


2

Try setting the mime type as well as shown in the manual for mail()

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
2012-04-04 17:22
by Jrod
another thing i would like to add, is never use aol,hotmail,yahoo,gmail or any other well know email in the from header, because godaddy mail server rejects them - engma 2012-11-03 16:18


0

as Jrod already answered you need to add the header

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

but I found that this one is screwing mine up as of late and had to comment it out:

$headers  = 'MIME-Version: 1.0' . "\r\n";
2012-04-27 23:05
by boris
Ads