Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Username and Password not accepted. SMTP could not authenticate. #1708

Closed
lmnlis opened this issue Apr 15, 2019 · 11 comments
Closed

Username and Password not accepted. SMTP could not authenticate. #1708

lmnlis opened this issue Apr 15, 2019 · 11 comments

Comments

@lmnlis
Copy link

lmnlis commented Apr 15, 2019

I have been finding an answer for a day now and I can't still figure out what is wrong with my code.
I am running phpmailer on a free live hosting site (infinityfree) and i have trouble figuring out the problem to send emails. I am receiving the error below. I made sure everything is not misspelled and had anything removed that should not be in code. Followed the instructions carefully. Tweaked settings in my google accounts as per the instructions on the troubleshooting guide . None of the worked so far.

Error

2019-04-15 00:13:03 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP 7sm165115092wrc.81 - gsmtp
2019-04-15 00:13:03 CLIENT -> SERVER: EHLO www.lisandrolaman.cf
2019-04-15 00:13:03 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [185.27.134.191]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2019-04-15 00:13:03 CLIENT -> SERVER: STARTTLS
2019-04-15 00:13:04 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2019-04-15 00:13:04 CLIENT -> SERVER: EHLO www.lisandrolaman.cf
2019-04-15 00:13:04 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [185.27.134.191]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2019-04-15 00:13:04 CLIENT -> SERVER: AUTH LOGIN
2019-04-15 00:13:04 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2019-04-15 00:13:04 CLIENT -> SERVER: <credentials hidden>
2019-04-15 00:13:04 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2019-04-15 00:13:04 CLIENT -> SERVER: <credentials hidden>
2019-04-15 00:13:04 SERVER -> CLIENT: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 https://support.google.com/mail/?p=BadCredentials 7sm165115092wrc.81 - gsmtp
2019-04-15 00:13:04 SMTP ERROR: Password command failed: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 https://support.google.com/mail/?p=BadCredentials 7sm165115092wrc.81 - gsmtp
SMTP Error: Could not authenticate.
2019-04-15 00:13:04 CLIENT -> SERVER: QUIT
2019-04-15 00:13:04 SERVER -> CLIENT: 221 2.0.0 closing connection 7sm165115092wrc.81 - gsmtp
SMTP Error: Could not authenticate.
Message could not be sent! Error: SMTP Error: Could not authenticate.

Below is my php code

<?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

if (isset($_POST['submit'])){

require_once 'vendor/autoload.php';

$mail = new PHPMailer(true);

try {



$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Username = '[email protected]';
$mail->Password = 'example';


$mail->setFrom($_POST['email'],$_POST['name']);
$mail->addAddress('[email protected]');
$mail->addReplyTo($_POST['email']);

$mail->isHTML(true);
$mail->Subject='Form Submission:';
$mail->Body='<h1>Name :'.$_POST['name'].'<br>Email: '.$_POST['email']. '<br>Message: 
'.$_POST['message'].'</h1>';

$mail->send();
echo 'Message has been sent!';

} catch(Exception $e){
        echo "Message could not be sent! Error: {$mail->ErrorInfo}"; 
}
 }


?>
@Synchro
Copy link
Member

Synchro commented Apr 15, 2019

This exact problem is dealt with in detail in the troubleshooting guide; it's most likely that you need to visit the "unlock captcha" page.

@Synchro Synchro closed this as completed Apr 15, 2019
@lmnlis
Copy link
Author

lmnlis commented Apr 15, 2019

Thanks for the response. I actually have visited the unlock captcha page already and enable my access to other apps but it does not work in my case. i tried yahoo smtp also receiving the same error. i have it uploaded on my website. it's on my contact form. www.lisandrolaman.cf

@keaikitse
Copy link

@lmnlis is it working ? I did enable third party access to mine

@officialSinosoft
Copy link

please av been stuck with this same issue. can you show me the get past this problem.

@lmnlis is it working ? I did enable third party access to mine

how did you go about this?
mmmmmmmmmmmmmmm

@gkurl
Copy link

gkurl commented Nov 11, 2019

please av been stuck with this same issue. can you show me the get past this problem.

@lmnlis is it working ? I did enable third party access to mine

how did you go about this?
mmmmmmmmmmmmmmm

I am having this exact same issue. Have taken the steps to unlock captcha, turned on less secure apps access even. But am still receiving the username password failed error message. Have used the gmail PHPMailer template.

@gkurl
Copy link

gkurl commented Nov 11, 2019

Update: Ok for some reason my "Less secure apps" setting was not updated properly. My mail is now sending. To get around this you have to enable in your google account Less secure app access. Just login to your google account, in the search bar type in "app" and from the drop-down choose the "Less secure app access" and turn it on.

@azmiabubakar
Copy link

thanks a million gkurl, I'd stuck with the same issue for days. Tried your solution...voila mail sent.

Milion thanks again.

@PHPMailer PHPMailer deleted a comment from raf-cpu Jun 11, 2020
@gabrielfreirebraz
Copy link

gabrielfreirebraz commented Jun 18, 2020

Obrigado @gkurl , sua solução me ajudou muito.

Para quem estiver com esse problema também, segue link de passo a passo do Google. Em seguida, vá até a seção "Remover o acesso do site ou app".

@somgaur
Copy link

somgaur commented Jan 4, 2021

Error 1: Password Command Failed: 534-5.7.9 Application-Specific Password Required
Error 2: SMTP ERROR: Password Command Failed: 535-5.7.8 Username And Password Not Accepted

This happens mostly when SMTP Mail Server Credentials were correct but Application Specific Password was not provided.

Create App Specific Password From Here and pasate it in place of gmail password
https://support.google.com/mail/answer/185833?hl=en

@briandanaa
Copy link

Update: Ok for some reason my "Less secure apps" setting was not updated properly. My mail is now sending. To get around this you have to enable in your google account Less secure app access. Just login to your google account, in the search bar type in "app" and from the drop-down choose the "Less secure app access" and turn it on.

thanks so much....... love x bts

@ahmedsaheed
Copy link

ahmedsaheed commented Apr 23, 2022

the less secure app access is now deprecated see here @somgaur answer looks more correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants