首页 > 解决方案 > SMTP:客户端:535 5.7.3 身份验证不成功

问题描述

每次有人在我的网站上输入表格但SMTP不起作用时,我都会尝试发送电子邮件。它不断向我显示此错误。电子邮件帐户的凭据是正确的。另外,我已经尝试过SMTPAuth = False;了,但结果还是一样。

<?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];  


    // Import PHPMailer classes into the global namespace
    // These must be at the top of your script, not inside a function
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;

    //Load Composer's autoloader
    require 'vendor/autoload.php';

    $mail = new PHPMailer(true);                              
    try {
        //Server settings
        $mail->SMTPDebug = 2;                                
        $mail->isSMTP();                                 
        $mail->Host = 'smtp.office365.com';  
        $mail->Port = 587;                               
        $mail->SMTPSecure = 'TLS';        
        $mail->SMTPAuth = true;                               
        $mail->Username = 'sender@test.com';                 // SMTP username
        $mail->Password = 'password';                        // SMTP password


        //Recipients
        $mail->setFrom('test@test.com', ' Services');
        $mail->addAddress('recipient@test.com', $name);     // Add a recipient


        //Content
        $mail->isHTML(true);                       // Set email format to HTML
        $mail->Subject = 'Contact Us Message';
        $mail->Body    = 'Sent a message, This is the message :';
        $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

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

出了什么问题?谢谢你的帮助。

标签: phphtmlsmtp

解决方案


我也在为同样的问题苦苦挣扎 2 天。在我找到这个解决方案之后。它工作正常。尝试这个。

$mail->Host = 'smtp.office365.com'; 更改为 $mail->Host = 'smtp.live.com';


推荐阅读