无法使用HTML格式化PHP电子邮件

时间:2014-04-04 20:12:12

标签: php html html-email

出于某种原因,当我发送电子邮件时,HTML仍然以纯文本显示。有人可以告诉我这里我做错了什么吗?

以下是代码:

            $to = $_SESSION['customer_email']; 
            $from = "noreplay@mysite.com";
            $subject = "Confirmation for Appointment on ".$_SESSION['display_date'];

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

              $message =  "<p>Thank you".$_SESSION['firstname']." for booking online. Your appointment has been confirmed and is scheduled for <strong>".$_SESSION['display_date']."</strong> between the hours of <strong>".$_SESSION['display_time']."</strong>.</p><p>  Please expect our crew to arrive between your two hour arrival window.  You will receive a courtesy call when our crew is <span>15-30 minutes</span> away. A confirmation email has been sent to <strong>".$_SESSION['customer_email']."</strong>. </p><p> If you have any questions or need to make any changes to your appointment, please contact our office at <strong>1-800-333-1111</strong>.  Thank you for choosing Us!
</p>";


            if(mail($to, $subject, $message, $header ))
            {
                $msg = "Your message has been sent";
            }

3 个答案:

答案 0 :(得分:3)

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

应该是

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

答案 1 :(得分:2)

两个错别字:

if(mail($to, $subject, $message, $header ))

应该是

if(mail($to, $subject, $message, $headers ))

并在

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

答案 2 :(得分:1)

将您的'charseet'更改为 <击>

<击>
Content-Type: text/html; charset=ISO-8859-1\r\n

<击> 现在看来你可以使用UTF-8

Content-Type: text/html; charset=UTF-8\r\n

if(mail($to, $subject, $message, $header))

if(mail($to, $subject, $message, $headers))

mail的回归:

  

如果邮件成功接受传递,则返回TRUE,否则返回FALSE。   重要的是要注意,仅仅因为邮件被接受交付,它   并不意味着邮件实际上会到达预定目的地。