Gmail settings Google Gmail does not allow sending emails with PHPMailer

I created an account in Gmail (because the previous problem was giving me the same problem) so that my app can send emails using Google's SMT server.

I am using PHPMailer library and am asking to show log errors.

I always get a message like this. This is slightly different, sometimes shorter and sometimes longer depending on my configuration.

2015-08-01 05:07:01 CLIENT -> SERVER: EHLO 
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 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. string(82) "SMTP connect() failed."


This is my script

    $mail->Username = "";
    $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 = "";
    $mail->Port = 465; // or 587
    $mail->SetFrom($mail->Username, 'Contato Lavile');
    $mail->addAddress($mail->Username, "Contato Lavile");
    $mail->Subject = 'Novo contato no site Lavile';
    $mail->Body = $text;
    $mail->AltBody = $text;


GMAIL also sends me automatic emails warning me that a new login attempt has been blocked. I even changed some settings in my gmail to make it work but it all failed

Any ideal? Do you know what can happen?


source to share

4 answers

I would recommend to actually read the error message:

... 534-5.7.9 Log in to your web browser and try again. More details at 534 5.7.9 b16sm3352387qga.48 - gsmtp

As you read this site, you will find something about customer support that only provide less secure authentication methods. Your client is one of them, so follow the link to find out how to enable support for these apps in gmail.



You can send email without your own smtp server: 1) get recipient mx hostname from dns 2) send email to port 25



Not to say this is necessarily what happened to the theme opener, but I had the exact same error today. And the reason I got this was because I created a new email and you first need to login to Gmail once through your browser before you can use smtp.

After logging into the Gmail web client through a browser and going through the initial flow, I was able to send it through the smtp endpoint.



$mail->Host = "";

should look something like this:

$mail->Host = "";//replace your domain name




All Articles