2014-04-04 29 views
0

由於某些原因,當我發送電子郵件時,HTML仍以純文本形式顯示。有人可以告訴我我在做什麼錯嗎?無法使用HTML格式化PHP電子郵件

下面是代碼:

  $to = $_SESSION['customer_email']; 
      $from = "[email protected]"; 
      $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"; 
      } 

回答

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。 重要的是要注意,僅僅因爲郵件被接受交付,它並不意味着郵件實際上會到達預定的目的地。

+0

謝謝。我覺得自己像個白癡。 – BlackHatSamurai

2

兩個錯別字:

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

應該

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

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

應該

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