发送HTML电子邮件错误内容类型或mime类型

时间:2013-08-27 00:14:43

标签: html email mime-types content-type

我无法将此电子邮件显示在Gmail中。

代码以纯文本显示,因此我知道邮件服务器没有任何问题。但是,我需要我的用户确认链接,但我不能让这些html元素出现。我已尝试过从mime设置到内容类型的所有内容。

$to = $email; 
$from = "no-reply@alphaladys.com"; 
$subject = "Confirm Your Email"; 
$message = "<html><body>";
$message .= "
    <center> 
      <b>You are reiciving this email because you Signed up at Alphaladys.com</b> <br> 
      <font color=\"red\">Thank You, $name</font><br> 
      <b><a href=\"alphaladys.com/?71860c77c6745379b0d44304d66b6a13=emailVerify&key=$key\">Confirm Your Email</a></b><br>
    </center> 
    <br><br>© 2013 Copyright | AlphaLadys.Com |  All rights reserved.
"; 
$message .= "</body></html>";
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to, $subject , $message , $headers );

1 个答案:

答案 0 :(得分:0)

我已经在我的网络托管中测试了这个示例,它运行正常:

<?php 

$from = "xxxxx@gmail.com"; 
$subject = "Confirm Your Email"; 
$message = "<html><body>";
$message .= "
    <center> 
      <b>You are reiciving this email because you Signed up at Alphaladys.com</b> <br> 
      <font color=\"red\">Thank You, $name</font><br> 
      <b><a href=\"alphaladys.com/?71860c77c6745379b0d44304d66b6a13=emailVerify&key=$key\">Confirm Your Email</a></b><br>
    </center> 
    <br><br>© 2013 Copyright | AlphaLadys.Com |  All rights reserved.
"; 
$message .= "</body></html>";
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
if(mail($from, $subject , $message , $headers )) echo 'Mail sent :)';
    else echo 'Mail not sent :(';}

?>

结果: Result