PHPMailer雅虎邮件转到垃圾邮件箱

时间:2018-08-28 17:43:29

标签: php

我通过邮件PHPMailer库发送SMTP

除Yahoo进入垃圾邮件框外,所有电子邮件提供商(例如gmail)都是正确的。

我的代码是:

//****** START CONFIG ******
$templateFile = "email-template.php";
$IS_DEBUG = true;

$SMTP_HOST = 'mail.site.com';
$SMTP_PORT = 587;
$SMTP_USERNAME = 'no-reply@site.com';
$SMTP_PASSWORD = 'mypassword';

$MAIL_SUBJECT = 'Activation Code';
$MAIL_FROM_ADDRESS = 'no-reply@site.com';
$MAIL_FROM_NAME = 'MySite.com';
//****** END CONFIG ******

$code = !empty($_GET['code']) ? $_GET['code'] : '';
$mailAddress = !empty($_GET['mail']) ? $_GET['mail'] : '';

require "MailClasses/PHPMailer.php";
require "MailClasses/Exception.php";
require "MailClasses/SMTP.php";

use PHPMailer\PHPMailer\PHPMailer;

$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$content = file_get_contents(dirname($actual_link) . "/$templateFile?code=$code&subject=" . urlencode($MAIL_SUBJECT));



$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->CharSet = "utf-8";// set charset to utf8

$mail->SMTPDebug = $IS_DEBUG ? 2 : 0;
$mail->Host = $SMTP_HOST;
$mail->Port = $SMTP_PORT;
$mail->SMTPAuth = true;
$mail->Username = $SMTP_USERNAME;
$mail->Password = $SMTP_PASSWORD;

$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);

$mail->SMTPSecure = "tls";

$mail->isHTML(true);

$mail->setFrom($MAIL_FROM_ADDRESS, $MAIL_FROM_NAME);

$mail->Subject = $MAIL_SUBJECT;

$mail->msgHTML($content, __DIR__);

$mail->addReplyTo($MAIL_FROM_ADDRESS, $MAIL_FROM_NAME);

$mail->addAddress($mailAddress);

$mail->Priority = 1;
$mail->AddCustomHeader("X-MSMail-Priority: High");
$mail->From = $MAIL_FROM_ADDRESS;
$mail->FromName = $MAIL_FROM_NAME;


//send the message, check for errors


    if (!$mail->send()) {
        //echo 'Mailer Error: ' . $mail->ErrorInfo;
        die("Fail");
    } else {
        //echo 'Message sent!';
        die("Activate");
    }

我该如何解决?我需要它进入收件箱。

感谢帮助。

0 个答案:

没有答案