2014-04-03 43 views
-1

我正嘗試發送表單上的電子郵件提交給我工作的客戶,但他正在分手。該電子郵件顯示了html標籤。電子郵件模板分解。顯示HTML標籤

模板:

<!doctype html> 
<html> 
<head> 
<meta charset="utf-8"> 
</head> 
<body> 
<div> 
<h1>New Tour Request</h1> 
<hr> 

<b> Registration For:</b> {{ tour_name|default('N/A')|escape }} <br> 
    <h3> Total Adults:</h3> {{ adult_passengers|default('N/A')|escape }} <br> 

    {% if(adult_passengers > 0) %} 

    {% for i in 1 .. adult_passengers %} 

     <b>First Name:</b> {{ adult_first_name[i-1]|default('N/A')|escape }}<br> 
     <b>Last Name:</b> {{ adult_last_name[i-1]|default('N/A')|escape }}<br> 

    {% endfor %} 

    {% endif %} 

<h3>Total Children:</h3> {{ child_passengers|default('N/A')|escape }}<br> 

    {% if(child_passengers > 0) %} 

    {% for i in 1 .. child_passengers %} 

      <b>First Name:</b> {{ child_first_name[i-1]|default('N/A')|escape }}<br> 
      <b>Last Name:</b> {{ child_last_name[i-1]|default('N/A')|escape }}<br> 

    {% endfor %} 

    {% endif %} 

    <b>Departure Date:</b> {{ departure_date|default('N/A')|escape }}<br> 
    <b>Departure City:</b> {{ departure_city|default('N/A')|escape }}<br> 
    <b>Flexibility:</b> {{ departure_flexibility|default('N/A')|escape }}<br> 
    <b>Earliest date I can leave:</b> {{ depart_day|default('N/A')|escape }}<br> 
    <b>Latest date I can be back:</b> {{ back_day|default('N/A')|escape }}<br> 
    <b>Email Address:</b> {{ email_address|default('N/A')|escape }}<br> 
    <b>Telephone:</b> {{ tel1 ~ tel2 ~ tel3 }}<br> 
    <b>Message:</b> {{ special_message|default('N/A')|escape }}<br> 
</div> 
</body> 
</html> 

這是客戶端是如何接收電子郵件

"\n\n\n \n<\/head>\n\n 
\n\n 
New Tour Request<\/h1>\n 

\n\n 
\n 
Registration For: Trip Title <\/li> \n 
Total Adults: 1 <\/li>\n<\/ul> \n \n 
\n 
First Name:<\/b> CustomerFN <\/li>\n 
Last Name:<\/b> CustomerLN <\/li> 

\n <\/ul>\n \n <\/ul>\n 
\n 
Total Children: 0<\/li>\n <\/ul> \n 
\n 
Departure Date: 04\/02\/2014<\/li>\n 
Flexibility: <\/li>\n 
Earliest date I can leave: 04\/03\/2014<\/li>\n 
Latest date I can be back: 04\/25\/2014<\/li>\n 
Email Address: [email protected] <\/li>\n 
Telephone: 1111111111<\/li>\n 
Message: Testing Message <\/li>\n 

我也嘗試使用這個format發送電子郵件,但它只是顯示 「\ n \ n \ n」沒有別的。我不知道可能是什麼問題,但它確實很奇怪。

+0

您需要設置您的[mime版本和內容類型](http://stackoverflow.com/questions/3058897/sending-html-email-from-php)將內容呈現爲html – John

+0

在哪裏添加它們@約翰 - 我嘗試添加在模板文件中,但它沒有工作 – user3339224

+0

你是如何發送它?他們提交表單時發送的代碼是什麼?這裏是另一個很好的[PHP教程](http://css-tricks.com/sending-nice-html-email-with-php/) – John

回答

1

您的郵件功能應該是這樣的:

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

通過這樣的$headers變量:

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

(若郵件功能之前定義)

希望工程。