使用 phpmailer 从 Gmail 发送电子邮件。登录错误

Lew*_*ris 2 php email gmail smtp

我似乎无法理解为什么我不能使用 php 中的各种邮件类发送电子邮件。我知道我的密码等是正确的。

谁有想法?

我收到错误:

SMTP -> 错误:服务器不接受密码:534-5.7.14 请通过您的网络浏览器和 534-5.7.14 登录,然后重试。534-5.7.14 在 534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 dm6sm8657044wib.22 - gsmtp SMTP 错误:无法验证。邮件程序错误:SMTP 错误:无法进行身份验证。

function mail1($to,$body,$subject){

    include "/libs/mailer/classes/class.phpmailer.php"; // include the class name
    $mail = new PHPMailer(); // create a new object
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true; // authentication enabled
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
    $mail->Host = "smtp.gmail.com";
    $mail->Port = 465; // or 587
    $mail->IsHTML(true);
    $mail->Username = "lewis.morris@gmail.com";
    $mail->Password = "xxxxxxxx";
    $mail->SetFrom("lewis.morris@gmail.com");
    $mail->Subject = $subject;
    $mail->Body = $body;
    $mail->AddAddress($to);

    if(!$mail->Send()){
        echo "Mailer Error: " . $mail->ErrorInfo;
    }
    else{
        echo "Message has been sent";
    }

}
Run Code Online (Sandbox Code Playgroud)

Bis*_*kar 7

此链接总是帮助我解决从我的应用程序登录到 gmail 的任何类型的问题。试试这个可能对你有帮助...

在这里,关闭不太安全的应用程序的日志记录:https : //www.google.com/settings/u/1/security/lesssecureapps

在这里,只需点击继续... https://accounts.google.com/b/0/DisplayUnlockCaptcha

并在此处检查您的帐户是否有任何日志记录:https : //security.google.com/settings/security/activity?hl=en&pli=1

而且,运行你的代码..