2017-08-27 97 views
0

我需要幫助將電子郵件中的FROM字段設置爲特定的電子郵件地址。截至目前,它正在出現這樣的事情。看起來像它從我的託管公司服務器獲取信息。PHP電子郵件標題FROM字段顯示不正確

[email protected]

偉大的電子郵件工作的所有其他功能。我的$headers如下:

$to = $email; 
$subject = "ORDER # $tranid"; 
$headers = "From: [email protected]"; 
$headers = "MIME-Version: 1.0"; 
$headers = "Content-type: text/html; charset=iso-8859-1"; 

PHP手冊sugest this。我想,這正是我正在做的事情。

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

他們確實使用破滅,但我不認爲我需要它的方式我有我的設置:

mail($to, $subject, $message, implode("\r\n", $headers)); 

試圖與沒有成功:

$to = $email; 
$subject = "ORDER # $tranid"; 
$headers .= "From: [email protected]"; 
$headers .= "MIME-Version: 1.0"; 
$headers .= "Content-type: text/html; charset=iso-8859-1"; 
+0

您正在覆蓋每個標題。在第一個作業之後,你需要'。='。所以你的頭只是'Content-type:text/html;字符集=異8859-1'。 – chris85

+1

...和'implode'與數組一起工作,使用數組將更清潔。 – chris85

+0

嗯我剛剛試過這個 \t $ headers。='From:[email protected]​​oneparkprod.com'。 「\ r \ n」。 \t $ headers。=「MIME-Version:1.0」; \t $ headers。=「Content-type:text/html; charset = iso-8859-1」;但沒有什麼不同。但它確實使電子郵件不能正確看到我的HTML – NewCodeMan

回答

1

找到了在的幫助下回答@ chris85

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

保持HTML格式正確並顯示FROM字段。