這是我用來從網站上的聯繫表單發送電子郵件的完整代碼。 儘管所有的最佳實踐使用(標題等),結果是:防止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");
?>
https://support.google.com/mail/answer/81126?hl=zh-CN – mkaatman
嘗試使用swiftmailer發送它,我敢打賭問題消失。 – mkaatman