2017-04-05 222 views
0

這是我用來從網站上的聯繫表單發送電子郵件的完整代碼。 儘管所有的最佳實踐使用(標題等),結果是:防止PHP郵件發送到垃圾郵件gmail

1)確認電子郵件給用戶去在每次Gmail的垃圾郵件,它是已檢舉爲詐騙

2)管理員的電子郵件被標記作爲網絡釣魚

有人可以幫我嗎?謝謝!

<? 
// ----------------------------------------------------------------------------- 
// Website info 

    $SiteName = "www.example.com"; 
    $SiteWork = "Enterprise Name"; 
    $SiteMin = "Ent. name"; 
    $SiteEmail = "[email protected]"; 
    $SecondaryEmail = "[email protected]"; 
    $ThankYouMessage = "$SiteMin - Message sent!"; 
    $SiteTel = "Tel (+39) 0XX.XXXXXXX"; 
    $SiteFax = "Fax (+39) 0XX.XXXXXXX"; 
    $SiteSocial = "#..."; 
    $SiteAddress = "..."; 

// ----------------------------------------------------------------------------- 
// Retrieve contents 

    $UserSubject = $_POST['UserSubject']; 
    $UserName = $_POST['UserName']; 
    $UserCity = $_POST['UserCity']; 
    $UserEmail = $_POST['UserEmail']; 
    $UserComments = $_POST['UserComments']; 
    $UserAuth = $_POST['UserAuth']; 

// ----------------------------------------------------------------------------- 
// Set up user message 

    $UserMessage = "<html><head></head><body>"; 
    $UserMessage .= "<font size='6px'>"; 
    $UserMessage .= "Ciao $UserName,"; 
    $UserMessage .= "</font><br><br>"; 
    $UserMessage .= "<font size='4px'>"; 
    $UserMessage .= "abbiamo ricevuto il tuo messaggio.<br>"; 
    $UserMessage .= "Grazie per averci scritto, ti risponderemo al più presto.<br><br>"; 
    $UserMessage .= "</font><br>"; 
    $UserMessage .= "<img src='http://www.piazzaimpianti.it/img/logo.svg' width='60px'><br><br>"; 
    $UserMessage .= "$SiteWork $SiteAddress<br>"; 
    $UserMessage .= "$SiteTel - $SiteName - $SiteSocial<br>"; 
    $UserMessage .= "$SiteName<br>"; 
    $UserMessage .= "</body></html>"; 

    $UserHeaders = "From: $SiteEmail\r\n"; 
    $UserHeaders .= "Reply-To: $SiteEmail\r\n"; 
    $UserHeaders .= "Return-Path: $SiteEmail\r\n"; 
    $UserHeaders .= "CC:\r\n"; 
    $UserHeaders .= "BCC:\r\n"; 
    $UserHeaders .= "MIME-Version: 1.0\r\n"; 
    $UserHeaders .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
    $UserHeaders .= "X-Priority: 3\r\n"; 
    $UserHeaders .= "X-Mailer: PHP". phpversion() ."\r\n"; 

// ----------------------------------------------------------------------------- 
// Set up admin message 

    $AdminMessage = "Messaggio:\n"; 
    $AdminMessage .= "\n"; 
    $AdminMessage .= "$UserComments\n"; 
    $AdminMessage .= "\n\n"; 
    $AdminMessage .= "-------------------------------------------------\n"; 
    $AdminMessage .= "Dati utente:\n"; 
    $AdminMessage .= "-------------------------------------------------\n"; 
    $AdminMessage .= "$UserName \n"; 
    $AdminMessage .= "$UserEmail \n"; 
    $AdminMessage .= "$UserCity \n"; 
    $AdminMessage .= "-------------------------------------------------\n"; 
    $AdminMessage .= "Autorizzi il trattamento dei dati ai sensi del D.lgs.196/03 (*)? $UserAuth \n"; 
    $AdminMessage .= "-------------------------------------------------\n"; 
    $AdminMessage .= "Puoi rispondere al messaggio di $UserName\n"; 
    $AdminMessage .= "scrivendo all'indirizzo: $UserEmail\n\n"; 

// ----------------------------------------------------------------------------- 
// Send confirmation to contact page 

    $array['Sent'] = array('payload' => 'sent'); 
    echo json_encode($array); 

// ----------------------------------------------------------------------------- 
// Send the emails 

// confirmation email to user 
    mail($UserEmail, $ThankYouMessage, $UserMessage, $UserHeaders); 

// email to admin 
    mail("$SiteEmail", "$UserSubject", $AdminMessage, "From: $UserEmail"); 

?> 
+0

https://support.google.com/mail/answer/81126?hl=zh-CN – mkaatman

+0

嘗試使用swiftmailer發送它,我敢打賭問題消失。 – mkaatman

回答

1

您無法明確地控制您的電子郵件是否被標記爲垃圾郵件,但有些事情可以幫助您做。

  • 確保您的反向DNS是正確的。
  • 執行SPF
  • 執行DKIM
  • 本地安裝SpamAssassin並通過詳細模式運行您的消息樣本,以瞭解它們爲什麼會被標記。
  • 使用類似MailChimpMailGun的服務而不是本地交付方。
2

您需要使用標題。這爲我工作:

$to = "[email protected]"; 
$subject = "your subject"; 
$body = "<p>Your Body</p>"; 
$headers = "From: Sender Name <[email protected]>" . "\r\n"; 
$headers .= 'MIME-Version: 1.0' . "\r\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
mail($to, $subject, $body, $headers); 

此外,您可以在您的註冊添加TXT RecordSPF,你有你的域名。進入DNS設置,並添加以下TXT記錄:

類型:TXT
主持人:example.com
值:v=spf1 ip4:YOUR.SERVER.IP.HERE ~all
TTL:Automatic

這是用來驗證該郵件沒有被欺騙。

+0

我已經在使用標題。現在我將嘗試在域中設置註冊。謝謝 –

相關問題