电子邮件不以HTML格式显示

时间:2015-08-11 11:06:32

标签: php email

我使用以下代码:

$useremail="xxx@gmail.com";
$admin_email="yyy@gmail.com";
$sub="some meassage";
$content=<design with tables>.................;

$reval=mail($useremail,$sub,$content,'From:'. $admin_email));

代码正确发送电子邮件,但它以文本格式显示而不是HTML格式,这就是我想要的。

我使用的是Content-type:

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From:'. $admin_email. "\r\n";
$reval=mail($useremail,$sub,$content,$headers);

在此方法中,电子邮件未送达。

1 个答案:

答案 0 :(得分:0)

尝试替换:

$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

通过:

$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

完整代码示例:

$useremail="xxx@gmail.com";
$admin_email="yyy@gmail.com";
$sub="some meassage";
$content = "Good morning,<br />
<strong>This is an HTML msg sent by php mail.</strong><br />
Thanks :)";

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"";
$headers .= 'From:'. $admin_email. "\r\n";

$reval=mail($useremail,$sub,$content,$headers);

if($reval)
{
    echo "mail sent";
}
else
{
    echo "error.";
}

它为我工作。