PHPMailer无法正常工作,发送垃圾邮件

时间:2018-10-30 11:45:48

标签: email phpmailer mailer email-spam

我写了一些代码来发送电子邮件,但这些被视为垃圾邮件。我使用Gmail进行了测试。任何人都可以帮助我找出问题所在吗?

我100%确定以下参数正确:

$mail->Host
$mail->Username
$mail->Password
$mail->Subject    (contains $subject)
$mail->Body       (contains $message)
$mail->setFrom
$mail->addReplyTo (equals $mail->setFrom)
$to               (contains mail recipient)

我还使用了$mail->addCustomHeader("BCC: bccmail@gmail.com")

代码下方。。我认为这是标题问题。

function php_mailer_send_mail ($to,$subject,$message) {
    $mail = new PHPMailer(true);                              // Passing `true` enables exceptions

    try {
        //Server settings
        $mail->SMTPDebug = 2;                                 // Enable verbose debug output
        // $mail->isSMTP();                                      // Set mailer to use SMTP
        $mail->Host = 'https://xxx.xxx.xxx.xxx:XXXX';  // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                               // Enable SMTP authentication
        $mail->Username = 'myUsername';                 // SMTP username
        $mail->Password = 'mypassword';                           // SMTP password
        $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
        $mail->Port = 587;                                    // TCP port to connect to

        //Recipients
        $mail->setFrom('emailfrom@mydomain.com', 'Keyword Translation Factory');
        $mail->addAddress($to, 'Welcome User');     // Add a recipient
        $mail->addReplyTo('emailfrom@mydomain.com', 'Keyword Translation Factory');
        // $mail->addCC('ccmail@gmail.com');
        $mail->AddBCC('bccmail@gmail.com');

        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = $subject;
        $mail->Body    = $message;
        $mail->AltBody = $message;

        $mail->send();
        // echo 'Message has been sent';
    } catch (Exception $e) {
        echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
    }
}

0 个答案:

没有答案
相关问题