0
我試圖發送電子郵件重置用戶密碼使用PHP郵件(),但它發送到垃圾郵件文件夾在Gmail帳戶獨自在雅虎郵件我可以得到此郵件收件箱內。我GOOGLE了一下,看到有些人說通過phpmailer使用smtp郵件服務器。郵件標記爲垃圾郵件獨自通過PHP郵件()以及smtp
我試過太多,但我得到相同的結果PHP mail()函數做了..在這裏我的PHP mail()函數的代碼
$headers = 'From: [email protected]' . "\r\n";
$headers .= 'Reply-To: '.$to.'';
$headers .= 'Subject: ' . $subject ." \r\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset="iso-8859-1"'. "\r\n";
@mail($to, $subject, $msg, $headers);
和php郵件的SMTP代碼
date_default_timezone_set('Etc/UTC');
require_once 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'mydomain.us';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 465;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'ssl';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "[email protected]";
//Password to use for SMTP authentication
$mail->Password = "pass";
//Set who the message is to be sent from
$mail->setFrom('[email protected]', 'sender name');
//Set an alternative reply-to address
$mail->addReplyTo('[email protected]', 'sender name');
//Set who the message is to be sent to
$mail->addAddress($to, 'John Doe');
//Set the subject line
$mail->Subject = $subject;
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML($msg);
//Replace the plain text body with one created manually
//$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
您的郵件是否以垃圾郵件結尾並不會與您發送郵件的方式有太大關係,而是與您發送的內容以及收件人的處理方式有關。如果收件人將其標記爲垃圾郵件,那麼gmail默認會開始這樣做。 Gmail幾乎將所有內容都標記爲垃圾郵件,而且情況越來越糟糕。 – Synchro