2014-03-13 89 views
1

我試圖在我的PHP表單中密件抄送電子郵件。出於某種原因,下面的代碼不發送的形式向BCC地址:從BCCPHP表單 - 密件抄送未收到電子郵件

$headers = "From: " . strip_tags($from) . "\r\n" . "BCC:[email protected]"; 
$headers .= "Reply-To: ". strip_tags($from) . "\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

除了沒有收到該電子郵件,形式的作品。對於BCC部分,我使用了接受的答案: Add BCC field to a php contact form

任何幫助表示讚賞。

回答

3

您的BCC不由\r\n分隔,因此回覆標題被連接到BCC值(使其無效)。

郵件服務器看到BCC標題爲:

BCC:[email protected]: [email protected] 

更改爲:

$headers = "From: " . strip_tags($from) . "\r\n" . "BCC:[email protected]\r\n"; 

旁註:strip_tags()是不夠的,以防止頭注入攻擊。您必須正確驗證來自電子郵件地址。

+0

謝謝MRCode - BCC領域現在的作品。你能指出我有關電子郵件地址驗證的任何教程嗎? – user3216933

+0

PHP5使用'filter_var'構建了電子郵件驗證。請參閱http://uk3.php.net/filter_var – MrCode

相關問題