BadCredentials when trying to send mail via SMTP using SwiftMailer in PHP

I am using SwiftMailer (https://swiftmailer.symfony.com/docs/introduction.html)

$transport = Swift_SmtpTransport::newInstance($host, $port, $security)
            ->setUsername(isset($pUsername) ? $pUsername : $pEmailGmail)
            ->setPassword($pPasswordGmail);
$mMailer = Swift_Mailer::newInstance($transport);
$mEmail = Swift_Message::newInstance();

But all of a sudden Im getting the error message :

<b>Fatal error</b>: Uncaught Swift_TransportException: Expected response code 250 but got code &quot;535&quot;, with message &quot;535-5.7.8 Username and Password not accepted. For more information, go to
535 5.7.8 https://support.google.com/mail/?p=BadCredentials af70cd14be357-7c5f66650desm180162285a.79 - gsmtp

I know for sure that the password is correct.

Solved Solved
0 6 450
2 ACCEPTED SOLUTIONS

@anjanesh 

I believe your issue is related to the fact that as of March 14, less secure apps using username and password no longer work. See https://support.google.com/a/answer/14114704?hl=en.

You should use a plugin/code/php library/etc. that supports OAUTH2 or look at app passwords: https://support.google.com/accounts/answer/185833?hl=en 

HTH, KAM

View solution in original post

Well, one note is that " App passwords can only be used with accounts that have 2-Step Verification turned on."  Do you have it turned on?  -KAM

View solution in original post

6 REPLIES 6

@anjanesh 

I believe your issue is related to the fact that as of March 14, less secure apps using username and password no longer work. See https://support.google.com/a/answer/14114704?hl=en.

You should use a plugin/code/php library/etc. that supports OAUTH2 or look at app passwords: https://support.google.com/accounts/answer/185833?hl=en 

HTH, KAM

Why is that I am unable to create an App Password ?

anjanesh_0-1743385066273.png

 

Well, one note is that " App passwords can only be used with accounts that have 2-Step Verification turned on."  Do you have it turned on?  -KAM

Got it - done and solved. Thanks.

@anjanesh was it the issue that you had to enable 2SV? -KAM

Yes KAM.

Top Solution Authors