2013-08-05 235 views
-1

我正在使用代碼發送帶附件的電子郵件,發送電子郵件,但事情是垃圾郵件。任何人都能猜出原因嗎?這是我的代碼:電子郵件附件垃圾郵件

$to = '[email protected]'; 
$subject = 'PHP Mail Attachment Test'; 
$bound_text = "jimmyP123"; 
$bound = "--".$bound_text."\r\n"; 
$bound_last = "--".$bound_text."--\r\n"; 

$headers = "From: [email protected]\r\n"; 
$headers .= "MIME-Version: 1.0\r\n" 
    ."Content-Type: multipart/mixed; boundary=\"$bound_text\""; 

$message .= "If you can see this MIME than your client doesn't accept MIME types!\r\n" 
    .$bound; 

$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n" 
    ."Content-Transfer-Encoding: 7bit\r\n\r\n" 
    ."hey my <b>good</b> friend here is a picture of regal beagle\r\n" 
    .$bound; 

$file = file_get_contents("http://reality.com/images/ezlogo.png"); 

$message .= "Content-Type: image/png; name=\"http://reality.com/images/ezlogo.png\"\r\n" 
    ."Content-Transfer-Encoding: base64\r\n" 
    ."Content-disposition: attachment; file=\"http://reality.com/images/ezlogo.png\"\r\n" 
    ."\r\n" 
    .chunk_split(base64_encode($file)) 
    .$bound_last; 
if(mail($to, $subject, $message, $headers)) 
{ 
    echo 'MAIL SENT'; 
} else { 
    echo 'MAIL FAILED'; 
} 
+4

如果它被標記爲垃圾郵件,這通常是*由於內容。如果您能夠掌握電子郵件垃圾郵件檢查的副本並查看原始郵件頭,它通常會說明電子郵件被標記爲垃圾郵件的主要原因。無論如何,這不是一個編碼問題 - 這是一個內容問題。 –

+0

可能重複[此帖](http://stackoverflow.com/questions/8075400/mail-generated-in-php-going-to-spam)。 – deepakb

+2

從不同於'from'電子郵件地址的服務器發送的電子郵件很容易被標記爲垃圾郵件。 – cgTag

回答

1

垃圾郵件過濾器的一個大問題是發送的html內容沒有形成良好的html主體。

即。您有部分

$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n" 
."Content-Transfer-Encoding: 7bit\r\n\r\n" 
."hey my <b>good</b> friend here is a picture of regal beagle\r\n" 
.$bound; 

您需要設置:

$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n" 
."Content-Transfer-Encoding: 7bit\r\n\r\n" 
."<html><head></head><body>hey my <b>good</b> friend here is a picture of regal beagle</body></html>\r\n" 
.$bound; 

它並不像它會帶來多大的改變,並在眼睛上,它沒有什麼區別,但它確實有所作爲過濾器。

要做的最好的事情就是讓電子郵件也被髮送到任何人,以「查看原文」,在那裏你得到的電子郵件的整個代碼,通常在標題中給出一個垃圾郵件分數和哪些測試失敗,爲您提供一些信息,說明您需要如何修復電子郵件才能通過。

+0

欣賞兄弟,當它改變郵件垃圾郵件停滯,但我的附件圖像顯示爲垃圾(BLOB)。我找不到我的依戀。 – nanbatman

+0

對不起,把''放在錯誤的地方,它們需要在\ r \ n'之前編輯回答才能反映出來,現在應該正確顯示附件 – bizzehdee

+0

哦!現在再次發送垃圾郵件,但附件很好。 – nanbatman

相關問題