2013-09-01 148 views
-1

我有下面的PHP代碼:從電子郵件中刪除HTML標記,德興電子郵件正文

<?php 
header('Content-Type: text/html; charset=utf-8'); 
if (isset($_POST['email'])) 
//if "email" is filled out, send email 
$name = $_POST['name']; 
$email = $_POST['email']; 
$phone = $_POST['phone']; 
$message = $_POST['message']; 
$formcontent="<html><body> 
<span style='background-color: #cdcdcd'> 
text: $name 
</span> 
text: $phone 
<span style='background-color: #cdcdcd'> 
text: $email 
</span> 
text: $message </html><body/>"; 
$recipient = "[email protected]"; 
$subject = "text text text "; 
$headers = "From: $email" . "\r\n" . 
    "Reply-To: $email" . "\r\n" . 
    'X-Mailer: PHP/' . phpversion(); 
mail($recipient, $subject, $formcontent, $headers) or die("Error!"); 
echo "Thank You!"; 
?> 

的問題是,wehn我收到的電子郵件,我看到在郵件正文中的所有HTML標籤,並且電子郵件不是造型。

我的問題是我該如何解決它?

回答

3

你沒有實際設置郵件中的Content-type頭標頭變量

$headers = "From: $email" . "\r\n" . 
"Reply-To: $email" . "\r\n" . 
"X-Mailer: PHP/" . phpversion() . "\r\n" . 
"Content-Type: text/html; charset=utf-8"; 

連接字符串

+0

我會注意到它,非常感謝! –

0

你需要$headerstext/htmlheader('Content-Type: text/html; charset=utf-8');

如果你沒有得到更好的答案,我以後會改善煤礦。目前時間短。

0

嘗試它的時候還去專門單引號,或雙引號 -

刪除線

header('Content-Type: text/html; charset=utf-8'); 

和替換

$headers = "From: $email" . "\r\n" . 
      "Reply-To: $email" . "\r\n" . 
      'X-Mailer: PHP/' . phpversion(); 

通過

$headers = "MIME-Version: 1.0\n"; 
$headers .= "Content-Type: text/html; charset=iso-8859-1\n"; 
$headers .= "From: $email" . "\r\n" . 
      "Reply-To: $email" . "\r\n" . 
      'X-Mailer: PHP/' . phpversion(); 
相關問題