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


Unable to format PHP email with HTML

由于某种原因,当我发送电子邮件时,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";
            }
 $headers .= "Content-type: text/html; charseet=UTF-8;'r'n";

应该是

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

两个错别字:

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

应该是

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

和在

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

将"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。 重要的是要注意,仅仅因为邮件被接受投递,它 并不意味着邮件将实际到达预定目的地。