2013-05-09 90 views
0

我正在通過下面的php代碼發送一封電子郵件,該代碼將電子郵件模板發送到用戶電子郵件地址。然而,電子郵件發送的所有HTML標籤仍然可見並且不起作用。使用PHP郵件格式化HTML()

$fh = fopen('templates/customer.eml','r'); 

     $emailContents = fread($fh, filesize('templates/customer.eml')); 
     $emailContents = str_replace(":name:", $person->first . " " . $person->last, $emailContents); 
     $emailContents = str_replace(":meeting_name:", $meeting->name, $emailContents); 
     $emailContents = str_replace(":chair:", $chair->first . " " . $chair->last, $emailContents); 

     fclose($fh); 

     $header = "FROM: [email protected]\r\n"; 
     $header = "MIME-Version: 1.0\r\n"; 
     $header.="Content-type: text/html; charset: utf8\r\n"; 
     mail($person->email , "Meeting Request", $emailContents, "FROM: [email protected]"); 

而下面是我使用的內容的電子郵件模板文件:

<html> 
    <head> 
     <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
    </head> 
    <body> 
     <p> 
      Dear :name:,<br /> 
      You have been invited to <em>:meeting_name:</em> chaired by :chair:. 
     </p> 

     <p> 
      Main text of the email will go here<sup>*</sup>. 
     </p> 
     <p> 
      Thankfully 
     </p> 
     <p> 
      User 
     </p> 
    </body> 
</html> 
+0

你不讀$頭變量。你只是追加到它。 – brunoais 2013-05-09 10:27:24

回答

1

你不及格頭到郵件功能。嘗試:

$header = "FROM: [email protected]\r\n"; 
$header .= "MIME-Version: 1.0\r\n"; 
$header .="Content-type: text/html; charset: utf8\r\n"; 
mail($person->email , "Meeting Request", $emailContents, $header); 

嘗試這些頭,而不是

$header = 'MIME-Version: 1.0' . "\r\n"; 
$header .= 'Content-type: text/html; charset=utf8' . "\r\n"; 
$header .= 'From: [email protected]' . "\r\n"; 
mail($person->email , "Meeting Request", $emailContents, $header); 
+0

對不起,我的錯誤。我已將$ header更新爲郵件功能。但是,我現在不收到和一封電子郵件? – Krisso123 2013-05-09 10:23:18

+0

感謝您發佈該代碼,它的工作:)真的很感謝您的幫助。謝謝 – Krisso123 2013-05-09 10:26:40