PHPMailer - 无法连接到 SMTP 主机

问题描述 投票:0回答:1

尝试使用 Gmail SMTP 服务器在 BlueHost VPS 上实施 PHPMailer。失败并显示“消息无法发送。邮件程序错误:SMTP 错误:无法连接到 SMTP 主机。”在我的 PHPMailer 谷歌帐户上有一个应用程序密码,该密码在脚本中使用。我尝试了许多端口和授权的组合,但出现同样的错误。没有产生其他错误消息(我可以找到)。

try 
    {
        //Server settings
        $mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
        $mail->SMTPAuth = true; // authentication enabled
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
        
        //Use GOOGLE SMTP Server
        $mail->Host = "smtp.gmail.com";
        $mail->Port = 587;          
        $mail->Username   = '[email protected]';                     //SMTP username
        $mail->Password   = '***app password***';              //SMTP password

        //Recipients
        $mail->setFrom('[email protected]', 'Mailer');
        $mail->addAddress('[email protected]', 'Good Person');     //Add a recipient

        //Content
        $mail->isHTML(true);                                  //Set email format to HTML
        $mail->Subject = 'Here is the subject';
        $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
        $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

        $mail->send();
        echo 'Message has been sent';
        exit;
    } 
    catch (Exception $e) 
    {
        echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
        exit;
    }    
smtp phpmailer
1个回答
0
投票

谢谢同步!解除端口阻塞后,我发现我的 use 语句有错误。现在通过 Gmail 发送电子邮件。

© www.soinside.com 2019 - 2024. All rights reserved.