I'm using PHPMailer in a Simple Script For Send Email's Through Gmail, and I'm getting an "Unknown Error" (At least for me!):
SMTP Error: Could not authenticate.
Error: SMTP Error: Could not
authenticate.
SMTP server error: 5.7.1 Username and
Password not accepted. Learn more at
535 5.7.1
http://mail.google.com/support/bin/answer.py?answer=14257
p38sm2467302ybk.16
I've read about Configure OpenSSL For SSL/TLS Connections, and I did it. Apache And PHP Are properly-Configured (With OpenSSL extension Running in PHP and mod_ssl running in Apache 2.2.16).
This is The PHP Script:
<?php
require_once ("PHPMailer\class.phpmailer.php");
$Correo = new PHPMailer();
$Correo->IsSMTP();
$Correo->SMTPAuth = true;
$Correo->SMTPSecure = "tls";
$Correo->Host = "smtp.gmail.com";
$Correo->Port = 587;
$Correo->UserName = "foo#gmail.com";
$Correo->Password = "gmailpassword";
$Correo->SetFrom('foo#gmail.com','De Yo');
$Correo->FromName = "From";
$Correo->AddAddress("bar#hotmail.com");
$Correo->Subject = "Prueba con PHPMailer";
$Correo->Body = "<H3>Bienvenido! Esto Funciona!</H3>";
$Correo->IsHTML (true);
if (!$Correo->Send())
{
echo "Error: $Correo->ErrorInfo";
}
else
{
echo "Message Sent!";
}
?>
The Username and Password are OK, And I tried in Thunderbird, without any problem.
I've also Used SSL Authentication and Port 465, getting the same Error.
I encountered this problem. To get it working, I had to go to myaccount.google.com -> "Sign-in & security" -> "Apps with account access", and turn "Allow less secure apps" to "ON" (near the bottom of the page).
Alternatively you can follow this direct link to these settings
this is GMail issue
read this Google Help (https://support.google.com/mail/answer/14257?p=client_login&rd=1)
Open your web browser and sign in to Gmail at http://mail.google.com/mail. If you see a word verification request, type the letters in the distorted picture and finish signing in.
Close your browser and try accessing your messages in your email client again.
If you're still having problems, visit http://www.google.com/accounts/DisplayUnlockCaptcha and sign in with your Gmail username and password. If necessary, enter the letters in the distorted picture.
Click Continue.
Restart your mail client and try accessing messages in your email client again.
Try this instead :
$Correo->Username = "foo#gmail.com";
I tested it and its working perfectly without no other change
I received the same error and in mycase it was the password. My password has special characters.
If you supply the password without escaping the special characters the error will persist.
E.g $mail->Password = " por$ch3"; is valid but will not work using the code above .
The solution should be as follows: $mail->Password = "por\$ch3";
Note the Backslash I placed before the dollar character within my password.
That should work if you have a password using special characters
Because Allow less secure apps is no longer available
The solution was to enable 2-step verification and generate app password
select mail and computer from the list then click generate
copy the code shown in the box and replace your google password with your app password it works like a charm.
I experienced the same error when configuring the WP-Mail-SMTP plugin in Wordpress.
The problem would persist even when I have 'triple checked' the settings and login credentials, and am able to log in manually using a browser.
There's a list of steps you can take to fix this.
Create a new password for the Gmail account you want to use
Enable less secure apps in Google Security settings
Use the Display Unlock Captcha page to give your app or website permission to sign in to Gmail. Click Continue or follow the instructions.
Sign in using the app or website. The smtp settings that work for me are 1) SMTP Host: smtp.gmail.com 2) SMTP port: 587 3) Encryption: TLS 4) Authentication: SMTP authentication 5) Username: example#gmail.com 6) Password: examplesecret
my solution is:
change gmail password
on gmail "Manage your google Account" > Security > Turn on 3rd party app Access
This the new step that i discover by UnlockingCaptcha that told in this site, the exact site is https://accounts.google.com/b/0/DisplayUnlockCaptcha, but maybe you want to read the former site first.
That all, hope it works for you
I received this error because of percentage signs in the password.
For me I had a special characters in my password field, and I put it like $mail->Password = " por$ch3" which work for gmail smpt server but not for other; so I just changed double quotes to single quotes and it works for me. $mail->Password = ' por$ch3';
If you still face error in sending email, with the same error message. Try this:
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
just Before the line:
$send = $mail->Send();
or in other sense, before calling the Send() Function.
Tested and Working.
The other post is correct to resolve the issue but doesn't address how to do it if the 2-step-verification is turned on. The option to allow the less secure apps is NOT available then. Here is an answer to how to do it:
a. Go to the URL of `https://myaccount.google.com/` and click `Sing-in and security`
b. Click on the app password.
You will reach a page like this,
c. Create name of your app and generate a password for the respective app.
d. Use that password acquired here inside the app.
This should resolve the issue.
I had the same issue and did all the tips including Gmail setting (e.g. less secure apps access) with no luck. But finally when I changed password to something different, for some reason it worked! FYI, the initial password did not have any special characters.
first go to https://myaccount.google.com
Select Security tab
Scroll down and select 'Less secure app access'
Turn on access
This will solve my “SMTP Error: Could not authenticate” in PHPMailer error.
I had the same issue and did all the tips with no luck. Finally when I changed password to something different, for some reason it worked! (the initial password or the new one did not have any special characters)
The correct answer:
Go to "Manage your google accounts => Security => Signing in to Google => App passwords".
Generate your maill account password there (that will be used from other device)
I had the same problem with authentication. The fix was to set up 2-step verification and create an application specific password for the device ( error messages for blocking the device will appear in your account settings->"Notifications and alerts" if you problem is the same with mine)
It was the selinux issue. I just updated the below given part in /etc/selinux/config file
SELINUX=permissive (it was SELINUX=enforcing before).
then just reboot the system by giving
reboot
Now the mail goes without any hassle.
Configuration
From Email Address : [noreply#yourdomain.com]
From Name : [your domain name]
SMTP Host : smtp.gmail.com
Type of Encryption : SSL
SMTP Port : 465
SMTP Authentication : YES
Username : [your mail id]
Password : [your password]
SMTP Error: could not authenticate
I had the same problem. The following troubleshooting steps helped me.
I turned off two-factor authentication in my gmail account.
I allowed less secure apps to access my gmail account. To get it working, I had to go to myaccount.google.com -> Sign-in & security -> Apps with account access, and turn Allow less secure apps to ON (near the bottom of the page).
At this step, when I tried to register a user, I would get the same error. Google would sent me a warning message that someone has my password and the login was blocked.
Gmail will then provide you with options. You either click whether the activity was yours or not yours. Click the option that the activity was yours.
Try registration again. It should now work.
There is no issue with your code.
Follow below two simple steps to send emails from phpmailer.
You have to disable 2-step verification setting for google account if you have enabled.
Turn ON allow access to less secure app.
I had the same issue which was fixed following the instructions below
Test enabling “Access for less secure apps” (which just means the client/app doesn’t use OAuth 2.0 - https://oauth.net/2/) for the account you are trying to access. It's found in the account settings on the Security tab, Account permissions (not available to accounts with 2-step verification enabled): https://support.google.com/accounts/answer/6010255?hl=en
original link for the answer: https://support.google.com/mail/thread/5621336?msgid=6292199
SOLVED
In 2022 the reason i found that
You need to do two-factor authentication in your mail service.
I am using Mail.ru https://account.mail.ru/user/2-step-auth/passwords/
Source:
https://www.courier.com/error-solutions/smtp-error-could-not-authenticate/
Related
Am trying to send email by Laravel.
But It's getting error.
.env file Configuration below :
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemailID#gmail.com
MAIL_PASSWORD=******
MAIL_ENCRYPTION=tls
Controller Code Below :
$data = array('name'=>"Ripon Uddin", "body" => "Test mail");
Mail::send('email', $data, function($message) {
$message->to('ToEmailID#yahoo.com','To My Yahoo')->subject('Laravel Test Email');
$message->from('ToFromID#gmail.com','Ripon Uddin (Laravel Lover)');
});
Error gettings :
Failed to authenticate on SMTP server with username "myEmailID#gmail.com" using 3 possible authenticators. Authenticator LOGIN returned Swift_TransportException: Expected response code 235 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials r18-v6sm7406256pgv.17 - gsmtp " in
you don't need to have GSuite to do this... I have done this integration alot of times with Laravel & GMail. Just go to your Google Account > Security > Less secure app access and Click on "Turn on access (not recommneded)"See image for more info
Go to this link or app password page of gmail then select 'mail' as "app" and custome name as "device". Then you will get app password.
Just go to your laravel mai.php under config folder in production or env file in dev mode. Paste the generated code on password section 'password' => 'generated code',
After all run: php artisan config:cache
Google changed its security policy. Now "Allow less secure apps" option is not available under Sign-in & security.
The idea is that Gmail does not allow any application to access a user's Gmail account, even with its real username and password. That's why people are getting the error. The new mechanism is you should create an application in your Google account and Google will generate a password for that application. Gmail will allow access with that Password and real username/Gmail ID.
The solution is
Step 1: sign-in to your Gmail account and to "Manage Your Account" as seen in the image below
Step 2: Click on the Security Tab in the left sidebar,
Step 3: Enable 2-step verification first for SMTP access.
You will not see "App Password" option until you enable 2-step verification.
After enabling 2-step verification click on "App Password". You will see like this
Click on the first dropdown and select "Other (Custom Name)". In the new window write your application name and git the Generate button. Copy the password that showed up.
Use this password, instead of your real Gmail password. SMTP configuration should look like
This config works on Gmail if you "Allow less secure apps" setting enabled in your gmail settings:
mailer_transport: smtp
mailer_host: smtp.gmail.com
mailer_port: 465
mailer_encryption: ssl
mailer_auth_mode: login
mailer_user: xxxx#xxxxxxx.com
mailer_password: "xxxx"
This one works on Gmail Suite if you white list the ip of your server in your gmail settings (see https://support.google.com/a/answer/2956491):
mailer_transport: smtp
mailer_host: smtp-relay.gmail.com
mailer_port: 587
mailer_encryption: tls
mailer_auth_mode: login
mailer_user: xxx#xxxxxxx.com
mailer_password: "xxxx"
Make sure your user credentials are right in .env file.
Try putting your passwords in quotes. eg: MAIL_PASSWORD="mypassword"
To apply your changes Run
php artisan config:cache
Did you turn on the "Allow less secure apps" on? go to this link
https://myaccount.google.com/security#connectedapps
Take a look at the Sign-in & security -> Apps with account access menu.
You must turn the option "Allow less secure apps" ON.
I am trying to run imap_open() in on my server but its giving me this error.
Warning: imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX in /home/bestinsaudi2/public_html/mailbox.php on line 55
Cannot connect to Gmail: Can not authenticate to IMAP server: [ALERT] Please log in via your web browser: https://support.google.com/mail/acco
I have enabled imap in gmail account i am using .I also enabled less secure apps. I copied code from david walsh . His credentials is giving this error.
Warning: imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX in /home/bestinsaudi2/public_html/mailbox.php on line 55
Cannot connect to Gmail: Can not authenticate to IMAP server: [AUTHENTICATIONFAILED] Invalid credentials (Failure)
I am writing down the code i am using with my own credentials.
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'myemail#gmail.com';
$password = 'mypassword';
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
here is one more thing i am not using wamp or xamp server i am using ipower. Somewhere i found to run command like $ composer require secit-pl/imap-bundle
And its confusing .How to and where to run this and is it necessary with my code? Also do i have to download any library for this ? or should some additional step?
If less secure apps are enabled, and the app password is not working or not desired, it might be that google has found the IP address that your imap is using to be suspicious and blocked it.
Log into that account from a browser and check for an email from that has the subject "Critical security alert". The date on the email should be around the same time that imap stopped working. If you find such an email, it should spell out that a sign-in attempt was blocked, and have a big button that says "Check activity". When you click the button, it will ask if the sign in that it blocked was actually from you. Indicate that it was, and you should be able to sign in with imap again from that IP.
If you or someone else has already indicated that it was or was not them, there is an option to change your answer.
When google decides to do this, it only sends a single email. So if it's been a few days, that email might be buried in the inbox. It does not get resent for each blocked sign in from that IP.
You are probably looking for gmail setup for something called "Less Secure Apps":
https://support.google.com/accounts/answer/6010255?hl=en
that's why it requires you to log in with a browser.
After you set this up correctly, and enable less secure apps, this should work nicely, just checked with my own account.
EDIT: is safe apps is alredy enabled, you may need to create App Password:
https://support.google.com/mail/answer/185833?hl=en
and change your credentials to:
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'email#gmail.com';
$password = 'app password here, not your gmail password';
EDIT2: App Password functionality require to have 2-Step verification enabled
I've got a symfony1 application with following factories.yml file:
mailer:
param:
delivery_strategy: realtime
transport:
class: Swift_SmtpTransport
param:
host: smtp.gmail.com
port: 465
encryption: ssl
username: my.user#gmail.com
password: my_password
password and username is correct, because I can use them to simply log in to gmail. I'm having trouble with symfony/swift mailer using gmail smtp to send mail. I'm submitting correct username/password, but google blocks, saying that the server is in Russia (giving the IP) and it says it doesn't trust it blah blah blah in case this was a security attack. Anyway, it's me and I just want to send emails using gmail.
The original gmail warning-email is in Polish, the translated version goes like this:
Someone recently used your password to log in to your Google Account
my.user # gmail.com. This person has received an
application (such as a client e-mail) or mobile device.
We blocked the logon attempt, in case someone wanted to break in to
your account. Check out these information:
Thursday, 12 December 2013 8:13:15 UTC IP address: 62.212.65.74
(s99.linuxpl.com.) Location: Russia
If you do not recognize the login attempts, someone else might try to
access your account. As soon as you log in and reset your password.
If this is you and you are having trouble accessing your account,
follow the troubleshooting instructions available on
http://support.google.com/mail?p=client_login
Regards, Google Accounts Team
And the link explains how to use smtp clients just like thunderbird, but it says nothing about software like swift mailer.
The symfony debug environment shows following error code:
Expected response code 250 but got code "530", with message "530-5.5.1 Authentication Required. Learn more at
530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 a51sm103278568eeh.8 - gsmtp
Does anyone know what can I do?
It seems strange, because there's no information about this at mentioned google links, but somehow I managed to find this information on the web:
you may try to visit https://accounts.google.com/DisplayUnlockCaptcha which displays a button that allows this gmail account to be accessed from a distant machine/device (other than the one you're just logged in now). I've pressed the button and retried mail sending and everything works now (the configuration remained 100% the same).
Hope it helps someone.
In my case it was a issue with security refer below
https://www.google.com/settings/security/lesssecureapps
I'm using PHPMailer in a Simple Script For Send Email's Through Gmail, and I'm getting an "Unknown Error" (At least for me!):
SMTP Error: Could not authenticate.
Error: SMTP Error: Could not
authenticate.
SMTP server error: 5.7.1 Username and
Password not accepted. Learn more at
535 5.7.1
http://mail.google.com/support/bin/answer.py?answer=14257
p38sm2467302ybk.16
I've read about Configure OpenSSL For SSL/TLS Connections, and I did it. Apache And PHP Are properly-Configured (With OpenSSL extension Running in PHP and mod_ssl running in Apache 2.2.16).
This is The PHP Script:
<?php
require_once ("PHPMailer\class.phpmailer.php");
$Correo = new PHPMailer();
$Correo->IsSMTP();
$Correo->SMTPAuth = true;
$Correo->SMTPSecure = "tls";
$Correo->Host = "smtp.gmail.com";
$Correo->Port = 587;
$Correo->UserName = "foo#gmail.com";
$Correo->Password = "gmailpassword";
$Correo->SetFrom('foo#gmail.com','De Yo');
$Correo->FromName = "From";
$Correo->AddAddress("bar#hotmail.com");
$Correo->Subject = "Prueba con PHPMailer";
$Correo->Body = "<H3>Bienvenido! Esto Funciona!</H3>";
$Correo->IsHTML (true);
if (!$Correo->Send())
{
echo "Error: $Correo->ErrorInfo";
}
else
{
echo "Message Sent!";
}
?>
The Username and Password are OK, And I tried in Thunderbird, without any problem.
I've also Used SSL Authentication and Port 465, getting the same Error.
I encountered this problem. To get it working, I had to go to myaccount.google.com -> "Sign-in & security" -> "Apps with account access", and turn "Allow less secure apps" to "ON" (near the bottom of the page).
Alternatively you can follow this direct link to these settings
this is GMail issue
read this Google Help (https://support.google.com/mail/answer/14257?p=client_login&rd=1)
Open your web browser and sign in to Gmail at http://mail.google.com/mail. If you see a word verification request, type the letters in the distorted picture and finish signing in.
Close your browser and try accessing your messages in your email client again.
If you're still having problems, visit http://www.google.com/accounts/DisplayUnlockCaptcha and sign in with your Gmail username and password. If necessary, enter the letters in the distorted picture.
Click Continue.
Restart your mail client and try accessing messages in your email client again.
Try this instead :
$Correo->Username = "foo#gmail.com";
I tested it and its working perfectly without no other change
I received the same error and in mycase it was the password. My password has special characters.
If you supply the password without escaping the special characters the error will persist.
E.g $mail->Password = " por$ch3"; is valid but will not work using the code above .
The solution should be as follows: $mail->Password = "por\$ch3";
Note the Backslash I placed before the dollar character within my password.
That should work if you have a password using special characters
Because Allow less secure apps is no longer available
The solution was to enable 2-step verification and generate app password
select mail and computer from the list then click generate
copy the code shown in the box and replace your google password with your app password it works like a charm.
I experienced the same error when configuring the WP-Mail-SMTP plugin in Wordpress.
The problem would persist even when I have 'triple checked' the settings and login credentials, and am able to log in manually using a browser.
There's a list of steps you can take to fix this.
Create a new password for the Gmail account you want to use
Enable less secure apps in Google Security settings
Use the Display Unlock Captcha page to give your app or website permission to sign in to Gmail. Click Continue or follow the instructions.
Sign in using the app or website. The smtp settings that work for me are 1) SMTP Host: smtp.gmail.com 2) SMTP port: 587 3) Encryption: TLS 4) Authentication: SMTP authentication 5) Username: example#gmail.com 6) Password: examplesecret
my solution is:
change gmail password
on gmail "Manage your google Account" > Security > Turn on 3rd party app Access
This the new step that i discover by UnlockingCaptcha that told in this site, the exact site is https://accounts.google.com/b/0/DisplayUnlockCaptcha, but maybe you want to read the former site first.
That all, hope it works for you
I received this error because of percentage signs in the password.
For me I had a special characters in my password field, and I put it like $mail->Password = " por$ch3" which work for gmail smpt server but not for other; so I just changed double quotes to single quotes and it works for me. $mail->Password = ' por$ch3';
If you still face error in sending email, with the same error message. Try this:
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
just Before the line:
$send = $mail->Send();
or in other sense, before calling the Send() Function.
Tested and Working.
The other post is correct to resolve the issue but doesn't address how to do it if the 2-step-verification is turned on. The option to allow the less secure apps is NOT available then. Here is an answer to how to do it:
a. Go to the URL of `https://myaccount.google.com/` and click `Sing-in and security`
b. Click on the app password.
You will reach a page like this,
c. Create name of your app and generate a password for the respective app.
d. Use that password acquired here inside the app.
This should resolve the issue.
I had the same issue and did all the tips including Gmail setting (e.g. less secure apps access) with no luck. But finally when I changed password to something different, for some reason it worked! FYI, the initial password did not have any special characters.
first go to https://myaccount.google.com
Select Security tab
Scroll down and select 'Less secure app access'
Turn on access
This will solve my “SMTP Error: Could not authenticate” in PHPMailer error.
I had the same issue and did all the tips with no luck. Finally when I changed password to something different, for some reason it worked! (the initial password or the new one did not have any special characters)
The correct answer:
Go to "Manage your google accounts => Security => Signing in to Google => App passwords".
Generate your maill account password there (that will be used from other device)
I had the same problem with authentication. The fix was to set up 2-step verification and create an application specific password for the device ( error messages for blocking the device will appear in your account settings->"Notifications and alerts" if you problem is the same with mine)
It was the selinux issue. I just updated the below given part in /etc/selinux/config file
SELINUX=permissive (it was SELINUX=enforcing before).
then just reboot the system by giving
reboot
Now the mail goes without any hassle.
Configuration
From Email Address : [noreply#yourdomain.com]
From Name : [your domain name]
SMTP Host : smtp.gmail.com
Type of Encryption : SSL
SMTP Port : 465
SMTP Authentication : YES
Username : [your mail id]
Password : [your password]
SMTP Error: could not authenticate
I had the same problem. The following troubleshooting steps helped me.
I turned off two-factor authentication in my gmail account.
I allowed less secure apps to access my gmail account. To get it working, I had to go to myaccount.google.com -> Sign-in & security -> Apps with account access, and turn Allow less secure apps to ON (near the bottom of the page).
At this step, when I tried to register a user, I would get the same error. Google would sent me a warning message that someone has my password and the login was blocked.
Gmail will then provide you with options. You either click whether the activity was yours or not yours. Click the option that the activity was yours.
Try registration again. It should now work.
There is no issue with your code.
Follow below two simple steps to send emails from phpmailer.
You have to disable 2-step verification setting for google account if you have enabled.
Turn ON allow access to less secure app.
I had the same issue which was fixed following the instructions below
Test enabling “Access for less secure apps” (which just means the client/app doesn’t use OAuth 2.0 - https://oauth.net/2/) for the account you are trying to access. It's found in the account settings on the Security tab, Account permissions (not available to accounts with 2-step verification enabled): https://support.google.com/accounts/answer/6010255?hl=en
original link for the answer: https://support.google.com/mail/thread/5621336?msgid=6292199
SOLVED
In 2022 the reason i found that
You need to do two-factor authentication in your mail service.
I am using Mail.ru https://account.mail.ru/user/2-step-auth/passwords/
Source:
https://www.courier.com/error-solutions/smtp-error-could-not-authenticate/
When I send an email with the PHP Swift mailer to this server: smtp.exchange.example.com like this:
// Load transport
$this->transport =
Swift_SmtpTransport::newInstance(
self::$config->hostname,
self::$config->port
)
->setUsername(self::$config->username)
->setPassword(self::$config->password)
;
// Load mailer
$this->mailer = Swift_Mailer::newInstance($this->transport);
// Initialize message
$this->message = Swift_Message::newInstance();
// From
$this->message->setFrom(self::$config->from);
// Set message etc. ...
// Send
$this->mailer->send($this->message);
I get a strange error back:
Failed to authenticate on SMTP server with username "user#example.com" using 2 possible authenticators
I know for sure that the login-info is correct.
This might be old but somebody might get help through this. I too faced the same problem and received a mail on my gmail account stating that someone is trying to hack your account through an email client or a different site.
THen I searched and found that doing below would resolve this issue.
Go to https://accounts.google.com/UnlockCaptcha
and unlock your account for access through other media/sites.
UPDATE : 2015
Also, you can try this, Go to https://myaccount.google.com/security#connectedapps
At the bottom, towards right there is an option "Allow less secure apps". If it is "OFF", turn it on by sliding the button.
UPDATE : 2021
The google URL has now changed to : https://myaccount.google.com/lesssecureapps. You will be asked to relogin
I had the same issue, so I've disabled one setting on my WHM root login, which is as follows :
WHM > Home > Server Configuration > Tweak Settings > Restrict outgoing SMTP to root, exim, and mailman (FKA SMTP Tweak) [?]
I really have the same problem, finally, i solved it.
its likey not the Swift Mail's problem. It's Yaml parser's problem.
if your password only the digits, the password senmd to swift finally not the same one.
swiftmailer:
transport: smtp
encryption: ssl
auth_mode: login
host: smtp.gmail.com
username: your_username
password: 61548921
you need fix it with double quotes
password: "61548921"
I just received the same error.
The strange thing is that commented the credential lines
// ->setUsername(self::$config->username)
// ->setPassword(self::$config->password)
And the problem disappeared.
I'm puzzled because the mail server definitely needs those credentials.
I tried almost all the possible suggestions mention here but for me problem got solved after changing "Access for less secure apps" to ENABLE in my Google account security settings tab. Hope this might useful for others !
The server might require some kind of encryption and secure authentication.
see http://swiftmailer.org/docs/sending.html#encrypted-smtp
try putting username in double quote "username", somehow that fixed for me.
I faced the same problem and solved it. Try to log in manually to your gmail account first.
This issue is due to google has detected your gmail account has been abusing. E.g send a lot of emails over a short period of time.
You perhaps use the wrong username.
I had a similar error. Ensure you're not using uppercase while logging into server.
Example: JacekPL#lala.pl
If you use ->setUsername('JacekPL'), this can cause an error. Use ->setUsername('jacekpl') instead. This solved my problem.
First check if there is any connectivity problem and you can reach the SMTP server:
In terminal type:
telnet servername portnumber
If you receive the 220 response you can reach the SMTP server and there is no connectivity problem but if the connection to the server failed see what's wrong in your network.
If the server needs auth try to authenticate on the server by username and password and see if something goes wrong.
At last see if the server requires encryption and if yes openssl and other stuff are configured correctly.
I got the same same error.
I was using gmail account and Google's SMTP server to send emails. The problem was due to SMTP server refusing to authorize as it considered my web host (through whom I sent email) as an intruder.
I followed Google's process to identify my web host as an valid entity to send email through my account and problem was solved.
If you are trying to send mail from your local enviroment eg. XAMPP or WAMP, this error will occur everytime, go ahead and try the same code on your web hosting or whatever you are using for production.
Also, 2 step authentication from google may be the issue.
Strange enough sending emails works again. We did not change anything and the host say they did not either. We think a server restarts or so. It is strange :S