2012-05-01 35 views
4

我在我的Ubuntu服務器上設置了PHP和Postfix。我需要從PHP腳本發送HTML電子郵件。該電子郵件發送得很好,但它顯示爲包含HTML標籤的純文本。另外,一些標題也顯示在電子郵件本身中。HTML郵件標題

我的猜測是,它與標題有關。我花了將近一天的時間尋找可能的解決方案,並且沒有找到一個解決方案。

這裏是PHP代碼:

$headers=''; 
$headers.="MIME-Version: 1.0 \r\n"; 
$headers.="Content-type: text/html; charset=\"UTF-8\" \r\n"; 
$headers.="From: ".FROM_EMAIL."\r\n"; 
mail($email, $vars['title'], $content, $headers); 

編輯:

$headers=''; 
$headers.='MIME-Version: 1.0'."\r\n"; 
$headers.='Content-type: text/html; charset=iso-8859-1'."\r\n"; 
$headers.='From: Kinesioteip.ee<'.FROM_EMAIL.'>'."\r\n"; 
$headers.='To: '.$email."\r\n"; 
mail($email, $vars['title'], $content, $headers); 

仍然沒有運氣...

+0

是$ content有效的html嗎? – 2012-05-01 10:38:08

+0

$ vars ['title']解釋這個 – srini

+0

Dagon,它足以在瀏覽器中工作。 –

回答

-1

我想是因爲沒有 '$' FROM_EMAIL變量的第四集是錯誤的

嘗試

 $headers.="From: ".$FROM_EMAIL."\r\n"; 

$瓦爾[ '標題']更改爲$ VAR

mail($email, $vars, $content, $headers); 
+0

夥計,FROM_EMAIL是一個常數,它不需要美元符號。我知道我傳遞給函數的變量是什麼,它們是正確的。 –

+0

你有什麼錯誤 – srini

4
$headers = 'MIME-Version: 1.0' . "\r\n"; 
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

    // Additional headers 
    $headers .= 'To:' . "\r\n"; 
    $headers .= 'From: Admin<[email protected]>' . "\r\n"; 
    // Mail it 
    mail($to, $subject, $message, $headers); 
+0

請再看看第一篇文章。我改變了標題,但沒有運氣。 –

2

你能嘗試這些線

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

更改爲

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

看看如果他們工作