无法发送消息。邮件程序错误:SMTP 错误:无法进行身份验证。在 php 中

时间:2021-07-14 17:03:02

标签: php html css

我遇到了一个非常便宜的问题,当我尝试在本地主机中运行我的应用程序时,它工作正常,但是当我将它上传到服务器上时,出现无法发送消息之类的错误。邮件程序错误:SMTP 错误:无法进行身份验证。

1)我已经正确地写了我的电子邮件和密码 2)我在

上做了较少的安全应用

请告诉我为什么会这样

 <?php
    
    use PHPMailer\PHPMailer\PHPMailer; 
    use PHPMailer\PHPMailer\Exception; 
    
    require 'vendor/autoload.php';
    
    if(isset($_POST['submit']))
    {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $subject = $_POST['subject'];
    $msg = $_POST['message'];
    
    $mail = new PHPMailer(true); 
    
    
    try { 
        $mail->SMTPDebug = 0;
        $mail->isSMTP();                                             
        $mail->Host  = 'smtp.gmail.com;';                    
        $mail->SMTPAuth = true;                          
        $mail->Username = '***********';                 
        $mail->Password = '*******';                         
        $mail->SMTPSecure = 'tls';                           
        $mail->Port  = 587;
    
        $mail->setFrom('nplus_01@gamil.com', '');        
        $mail->addAddress('nplus_01@gamil.com'); 
        $mail->addAddress('nplus_01@gamil.com', ''); 
        
        $mail->isHTML(true);                                 
        $mail->Subject = 'Subject'; 
        $mail->Body = "Name is $name <br> Email is $email <br> Subject is $subject <br> Message is $msg"; 
        $mail->AltBody = 'Body in plain text for non-HTML mail clients'; 
        $mail->send();  
        ?>
            <script>
                alert("Message Send Successfully");
            </script>
        <?php
    } catch (Exception $e) { 
        echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; 
    }
    }
    
    ?>

0 个答案:

没有答案