邮件错误:SMTP错误:无法验证。邮件错误:SMTP错误:无法验证

时间:2018-10-08 16:08:51

标签: phpmailer gsuite bluehost

我正在尝试使用PHPMailer和Bluehost上的G Suite帐户电子邮件发送消息,无法弄清楚为什么它不发送。

这是我得到的错误:Mailer错误:SMTP错误:无法认证。Mailer错误:SMTP错误:无法认证。

这是我的PHP代码:

public static function SendMail ($subject, $body, $alt_body, $to, $from, $reply_to = null)
{
    if (empty ($reply_to))
        $reply_to = $from;

    $mail = new PHPMailer (true);                               // Passing `true` enables exceptions

    try 
    {
        //Server settings
        $mail->SMTPDebug = 0;                                   // Enable verbose debug output
        $mail->isSMTP();                                        // Set mailer to use SMTP
        $mail->Host = 'mydomain.com';                           // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                                 // Enable SMTP authentication
        $mail->Username = 'mymail@mydomain.com';                // 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 ($from[key ($from)], key ($from));
        $mail->addAddress ($to[key ($to)], key ($to));          // Add a recipient
        $mail->addReplyTo ($reply_to[key ($reply_to)], key ($reply_to));

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

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

0 个答案:

没有答案