Google Gmail SMTP settings not allowing me to send emails with PHPMailer

10,871

I would recommend to actually read the error message:

... 534-5.7.9 Please log in with your web browser and then try again. Learn more at 534 5.7.9 https://support.google.com/mail/answer/78754 b16sm3352387qga.48 - gsmtp

When reading this site you will find something about supporting client which provide only less secure methods of authorization. Your client is one of these so follow the link to learn how to enable support for these application in gmail.

Share:
10,871
Victor Ferreira
Author by

Victor Ferreira

Web developer, majored in Information Systems and Informatics, now learning how to program for Android. In love with flat design.

Updated on June 04, 2022

Comments

  • Victor Ferreira
    Victor Ferreira almost 2 years

    I created an account on Gmail (becase the previous one was giving me the same problem) so that my application could send emails using google smtp server.

    I'm using the PHPMailer library and asked it to show any log errors.

    I always get a message similar to this. It vary a little, sometimes it is shorter and sometimes longer, depending on my configuration

    2015-08-01 05:07:01 CLIENT -> SERVER: EHLO www.lavile.com 
    2015-08-01 05:07:01 CLIENT -> SERVER: AUTH LOGIN 
    2015-08-01 05:07:01 CLIENT -> SERVER: Y29udGF0by5sYXZpbGVAZ21haWwuY29t 
    2015-08-01 05:07:01 CLIENT -> SERVER: WXlhdUgxMnM= 2015-08-01 05:07:01  SMTP ERROR: Password command failed: 534-5.7.9 Please log in with your web browser and then try again. Learn more at 534 5.7.9 https://support.google.com/mail/answer/78754 b16sm3352387qga.48 - gsmtp 
    2015-08-01 05:07:01 SMTP Error: Could not authenticate. 
    2015-08-01 05:07:01 CLIENT -> SERVER: QUIT 
    2015-08-01 05:07:01 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting string(82) "SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting"
    

    This is my script

        $mail->Username = "[email protected]";
        $mail->Password = "mypassword";
    
        $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->SetFrom($mail->Username, 'Contato Lavile');
        $mail->addAddress($mail->Username, "Contato Lavile");
        $mail->Subject = 'Novo contato no site Lavile';
        $mail->Body = $text;
        $mail->IsHTML(true);
        $mail->AltBody = $text;
    

    Also GMAIL is sending automatic emails to myself alerting me that a new login attempt was blocked. I even changed some settings on my gmail to make it work but everything failed

    Any idead? Do you know what could be happening?