php邮件不发送HTML内容

时间:2012-09-06 06:10:04

标签: php email

由于某些原因,我的php mail()函数不发送html,

而不是<a href="mysite">link</a>,它只显示link作为纯文本。

有什么想法吗?

这是我使用的标题:

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

// Additional headers
$headers .= 'From: My Automated Message <robot@mysite.cc>' . "\r\n";

并调用如下:

try {
    if (@mail($to_email, $subject, $message, $headers)){
        echo "<span style=\"color:#0D0; font:10pt Tahoma;font-weight:bold;\">{$SENT_MESSAGE}</span><br><br>"; 
        return true;
    } else {
        $tmp=error_get_last();
        throw new Exception($tmp['message']);
    }
} catch (Exception $e) {
    echo "<span style=\"color:red; font:10pt Tahoma;font-weight:bold;\">Error: ".$e->getMessage()."</span><br><br>";
}

我还尝试发送没有标题的邮件,但是再次将链接显示为纯文本,如下所示:<a href="mysite">link</a>

2 个答案:

答案 0 :(得分:1)

尝试此标题

  $headers = 'From: Name<address@domain.com>' . "\r\n" .
       'Content-Type: text/html; charset=UTF-8' . "\r\n" .
       'MIME-Version: 1.0' . "\r\n" .
       'Content-Transfer-Encoding: base64' . "\r\n" .
       'X-Mailer: PHP/' . phpversion();

答案 1 :(得分:0)

检查

 $from='robot@mysite.cc';      
 $headers ='';
 $headers .= 'MIME-Version: 1.0' . "\r\n";
 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 $headers .= 'From: '.$from.' '. "\r\n";

 mail($to_email, $subject, $message, $headers);