簡體   English   中英

由php mail()和smtp單獨將gmail標記為垃圾郵件的郵件

[英]Mail marked as spam by gmail alone by php mail() as well as smtp

我已經嘗試使用php mail()發送電子郵件以重置用戶密碼,但僅在yahoo郵件中將其發送到Gmail帳戶中的垃圾郵件文件夾,我可以在收件箱中獲取此郵件。 我用谷歌搜索,發現有些人說通過phpmailer使用smtp郵件服務器。

我也嘗試過,但是我得到了與php mail()函數相同的結果..這是我的php mail()函數代碼

$headers  = 'From: no-reply@mydomain.us' . "\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 = "cs@mydomain.us";

//Password to use for SMTP authentication
$mail->Password = "pass";

//Set who the message is to be sent from
$mail->setFrom('cs@umydomain.us.us', 'sender name');

//Set an alternative reply-to address
$mail->addReplyTo('cs@mydomain.us', '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!";
}

您的代碼看起來還可以,但是,如果服務器的IP地址已添加到用於過濾垃圾郵件的垃圾郵件黑名單中,則從服務器發送郵件的方式就無關緊要。

在Google上搜索“郵件服務器黑名單”之類的內容,然后測試服務器的IP地址以查看其是否已被列入黑名單。 如果您是從托管公司租用服務器,則更改之處是您的IP地址已被其他人使用。

您可以嘗試為您的公司創建一個測試Gmail帳戶,並嘗試使用具有SMTP的Gmail帳戶從服務器發送和發送電子郵件,然后查看電子郵件是否得到傳遞。 該電子郵件將代表您從Gmail服務器發送。

另一種選擇是使用類似郵寄API服務Mailgin

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM