首页 > 解决方案 > 错误:SMTP 错误:无法验证

问题描述

当我尝试使用 PHP SMTP 电子邮件服务器发送电子邮件时,出现以下错误。SMTP 错误:无法验证。无法发送消息。邮件程序错误:SMTP 错误:无法验证。

try {
            //Server settings
            $mail->isSMTP();                                            //Send using SMTP
            $mail->Host       = 'smtp.gmail.com';                     //Set the SMTP server to send through
            $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
            $mail->Username   = 'xxxx@gmail.com';                     //SMTP username
            $mail->Password   = 'xxxxxxx';                               //SMTP password
            $mail->SMTPSecure = 'tls';         //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
            $mail->Port       = 587;                                    //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
        
            //Recipients
            $mail->setFrom('tawiqha@gmail.com', 'reset');
            $mail->addAddress($email);     //Add a recipient
            $mail->addReplyTo('no-replay@gmail.com', 'no-replay');
            
            
            //Content
            $mail->isHTML(true);                                  //Set email format to HTML
            $mail->Subject = 'اعادة تعيين كلمة السر';
            $mail->Body    = $message;
            $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
        
            $mail->send();
            echo 'Message has been sent';
        } catch (Exception $e) {
            echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
        }

标签: phpphpmailer

解决方案


推荐阅读