一直在網上搜索,並嘗試了許多不同的解決方案,也使用phpmailer和其他庫。PHP郵件最終成爲gmail垃圾
我的目標是從我的網站發送一封確認郵件,它可以與Hotmail和其他服務一起使用,但使用Gmail最終會成爲垃圾郵件。
使用mail()
函數,頁面託管在one.com上,發送郵件確實存在。
代碼:
$mime_boundary = 'Multipart_Boundary_x'.md5(time()).'x';
$headers = "";
$headers .= 'MIME-Version: 1.0'."\r\n";
$headers .= "Content-Type: multipart/alternative; boundary=\"{$mime_boundary}\"\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";
$body = "This is a multi-part message in mime format.\n\n";
# Add in plain text version
$body .= "--{$mime_boundary}\n";
$body .= "Content-Type: text/plain; charset=\"charset=us-ascii\"\n";
$body .= "Content-Transfer-Encoding: 7bit\n\n";
$body .= "To view the message, please use an HTML compatible email viewer!";
$body .= "\n\n";
# Add in HTML version
$body .= "--{$mime_boundary}\n";
$body .= "Content-Type: text/html; charset=\"UTF-8\"\n";
$body .= "Content-Transfer-Encoding: 7bit\n\n";
$body .= $this->_message;
$body .= "\n\n";
$body .= "--{$mime_boundary}--\n"; #
$headers .= 'From: Sender <[email protected]>'."\r\n";
$headers .= 'Reply-To: Sender <[email protected]>'."\r\n";
$headers .= 'Return-Path: Sender <[email protected]>'."\r\n";
$headers .= 'Message-Id: <' . md5(uniqid(microtime())) . '@example.com>'."\r\n";
$headers .= "X-Sender-IP: ". $_SERVER['SERVER_ADDR'] ."\r\n";
$headers .= 'X-Mailer: PHP/'. phpversion() ."\r\n";
mail($this->_to, '=?UTF-8?B?'. base64_encode("Subject - ". $this->_subject) .'?=', $body, $headers, "-f [email protected]");
你有SPF記錄嗎?它與您的服務器相匹配嗎?你嘗試過DKIM嗎? – SLaks 2012-01-12 13:44:19
@Slaks是否也會查找DKIM記錄?但我知道SPF。 – greut 2012-01-12 13:45:41
@greut:我不知道,但它可能有幫助。 – SLaks 2012-01-12 13:46:48