0
可能重複:
How do you email source code without getting flagged as spam?
How can I lower the spam score of my email message?PHP - 電子郵件被標記爲垃圾郵件
我使用下面的代碼通過PHP附件的電子郵件。 (只是一箇中等大小的圖像和小的描述,沒有任何垃圾郵件內容)
問題是,一些服務標記爲垃圾郵件或完全拒絕它。
我是PHP新手,在SO上發現此代碼。標題有什麼問題或者是什麼原因造成的?
<?php
$file = $_POST["thefile"];
$text_message = $_POST["themessage"];
$subject = $_POST["thesubject"];
$from = $_POST["thesender"];
$to = $_POST["theaddress"];
$attachment=uniqid(rand(), true) . '.png';
$headers="From: $from\r\n";
$headers.="Reply-to: $from\r\n";
$headers.="Return-Path: $from\r\n";
if (isset($_ENV["SERVER_NAME"]))
$headers.="Message-Id: <" . md5(uniqid(microtime())) . "@" . $_ENV["SERVER_NAME"] . ">\r\n";
else
$headers.="Message-Id: <" . md5(uniqid(microtime())) . "@" . 'unknown' . ">\r\n";
$headers.="Date: " . date("r") . "\r\n";
$headers.="X-Mailer: PHP\r\n";
if (isset($_ENV["REMOTE_ADDR"]))
$headers.="X-SenderIP: " . $_ENV["REMOTE_ADDR"] . "\r\n";
else
$headers.="X-SenderIP: " . 'unknown' . "\r\n";
if (isset($_ENV["SERVER_NAME"]))
$headers.="X-WebSite: " . $_ENV["SERVER_NAME"] . "\r\n";
else
$headers.="X-WebSite: " . 'unknown' . "\r\n";
$headers.="X-Script: SWF_Generator\r\n";
$bound_text=md5(uniqid(time()));
$headers.="MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed; boundary=\"PHP-mixed-$bound_text\"\r\n";
$message="--PHP-mixed-$bound_text\r\n"
."Content-Type: text/html; charset=\"utf-8\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n"
."<html><head></head><body>"
."<div style=\"font-family: Arial, Helvetica, sans-serif; font-size : 1.3em; color: #000000;width: 100%;text-align: left;\">$text_message</div></body></html>\r\n\r\n"
."--PHP-mixed-$bound_text\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-Disposition: attachment; filename=\"$attachment\"\r\n"
."Content-Type: image/png; name=\"$attachment\"\r\n\r\n"
.chunk_split($file)
."\r\n\r\n"
."--PHP-mixed-$bound_text--\r\n\r\n";
mail($to,$subject,$message,$headers);
}
?>
謝謝。
發送通過信譽良好的電子郵件服務器,如您的Gmail帳戶.... – Baba
可能重複的[你如何通過電子郵件源代碼沒有被標記爲垃圾郵件?](http://stackoverflow.com/questions/1809082/how-do -you-email-source-code-without-getting-flagged-as-spam)或http://stackoverflow.com/questions/1860937/how-can-i-lower-the-spam-score-of-my-電子郵件?rq = 1 – hakre
巴巴說什麼。電子郵件是否進入垃圾郵件文件夾取決於接收電子郵件的提供商 - 而不是由誰發送。 – Abluescarab