Ошибка подключения к smtp серверу smtp error could not authenticate

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 ("PHPMailerclass.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.

Cœur's user avatar

Cœur

36.9k25 gold badges193 silver badges262 bronze badges

asked Oct 16, 2010 at 16:57

Alejandro Echeverri's user avatar

2

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

enter image description here

Joundill's user avatar

Joundill

6,72112 gold badges35 silver badges50 bronze badges

answered Sep 4, 2015 at 14:56

cwd's user avatar

7

Try this instead :

$Correo->Username = «foo@gmail.com»;

I tested it and its working perfectly without no other change

answered Oct 16, 2010 at 17:19

malletjo's user avatar

malletjomalletjo

1,78616 silver badges18 bronze badges

2

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

answered Aug 1, 2012 at 9:57

Bubba's user avatar

BubbaBubba

1011 silver badge7 bronze badges

2

Because Allow less secure apps is no longer available

enter image description here

The solution was to enable 2-step verification and generate app password

app

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.

app password

answered Jun 28, 2022 at 2:10

Kym NT's user avatar

Kym NTKym NT

6609 silver badges28 bronze badges

1

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.

  1. Create a new password for the Gmail account you want to use
  2. Enable less secure apps in Google Security settings
  3. Use the Display Unlock Captcha page to give your app or website permission to sign in to Gmail. Click Continue or follow the instructions.
  4. 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

Greg's user avatar

Greg

21.1k17 gold badges82 silver badges106 bronze badges

answered Jul 20, 2017 at 8:24

pyfork's user avatar

pyforkpyfork

3,6972 gold badges20 silver badges18 bronze badges

1

my solution is:

  1. change gmail password
  2. on gmail «Manage your google Account» > Security > Turn on 3rd party app Access
  3. 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

answered Jul 15, 2020 at 15:37

ibrahim saputra's user avatar

1

I received this error because of percentage signs in the password.

answered Dec 5, 2011 at 13:22

svandragt's user avatar

svandragtsvandragt

1,63320 silver badges38 bronze badges

1

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’;

answered Jun 11, 2013 at 12:17

Rikin Adhyapak's user avatar

3

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.

answered Jun 11, 2014 at 19:30

JackSparrow's user avatar

JackSparrowJackSparrow

9481 gold badge11 silver badges9 bronze badges

1

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. 

enter image description here

You will reach a page like this,

enter image description here

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.

answered May 20, 2018 at 10:16

Arefe's user avatar

ArefeArefe

11k18 gold badges110 silver badges165 bronze badges

0

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.

answered May 24, 2016 at 22:57

Ehsan's user avatar

EhsanEhsan

1,02211 silver badges20 bronze badges

  1. first go to https://myaccount.google.com
  2. Select Security tab
  3. Scroll down and select ‘Less secure app access’
  4. Turn on access

This will solve my “SMTP Error: Could not authenticate” in PHPMailer error.

answered Apr 29, 2020 at 13:07

ruwanmadhusanka's user avatar

ruwanmadhusankaruwanmadhusanka

8312 gold badges8 silver badges15 bronze badges

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)

answered Aug 18, 2019 at 14:06

user3809638's user avatar

0

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)

answered Apr 13, 2022 at 9:49

Gosforth's user avatar

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)

answered Jan 29, 2015 at 21:35

anu's user avatar

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]

answered Feb 10, 2016 at 7:17

Jathin Prasad's user avatar

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.

cSteusloff's user avatar

cSteusloff

2,4677 gold badges28 silver badges51 bronze badges

answered Dec 14, 2017 at 11:47

Joshua Mutinda's user avatar

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.

answered Apr 12, 2018 at 7:24

Ravindra Miyani's user avatar

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 ("PHPMailerclass.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.

Cœur's user avatar

Cœur

36.9k25 gold badges193 silver badges262 bronze badges

asked Oct 16, 2010 at 16:57

Alejandro Echeverri's user avatar

2

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

enter image description here

Joundill's user avatar

Joundill

6,72112 gold badges35 silver badges50 bronze badges

answered Sep 4, 2015 at 14:56

cwd's user avatar

7

Try this instead :

$Correo->Username = «foo@gmail.com»;

I tested it and its working perfectly without no other change

answered Oct 16, 2010 at 17:19

malletjo's user avatar

malletjomalletjo

1,78616 silver badges18 bronze badges

2

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

answered Aug 1, 2012 at 9:57

Bubba's user avatar

BubbaBubba

1011 silver badge7 bronze badges

2

Because Allow less secure apps is no longer available

enter image description here

The solution was to enable 2-step verification and generate app password

app

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.

app password

answered Jun 28, 2022 at 2:10

Kym NT's user avatar

Kym NTKym NT

6609 silver badges28 bronze badges

1

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.

  1. Create a new password for the Gmail account you want to use
  2. Enable less secure apps in Google Security settings
  3. Use the Display Unlock Captcha page to give your app or website permission to sign in to Gmail. Click Continue or follow the instructions.
  4. 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

Greg's user avatar

Greg

21.1k17 gold badges82 silver badges106 bronze badges

answered Jul 20, 2017 at 8:24

pyfork's user avatar

pyforkpyfork

3,6972 gold badges20 silver badges18 bronze badges

1

my solution is:

  1. change gmail password
  2. on gmail «Manage your google Account» > Security > Turn on 3rd party app Access
  3. 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

answered Jul 15, 2020 at 15:37

ibrahim saputra's user avatar

1

I received this error because of percentage signs in the password.

answered Dec 5, 2011 at 13:22

svandragt's user avatar

svandragtsvandragt

1,63320 silver badges38 bronze badges

1

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’;

answered Jun 11, 2013 at 12:17

Rikin Adhyapak's user avatar

3

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.

answered Jun 11, 2014 at 19:30

JackSparrow's user avatar

JackSparrowJackSparrow

9481 gold badge11 silver badges9 bronze badges

1

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. 

enter image description here

You will reach a page like this,

enter image description here

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.

answered May 20, 2018 at 10:16

Arefe's user avatar

ArefeArefe

11k18 gold badges110 silver badges165 bronze badges

0

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.

answered May 24, 2016 at 22:57

Ehsan's user avatar

EhsanEhsan

1,02211 silver badges20 bronze badges

  1. first go to https://myaccount.google.com
  2. Select Security tab
  3. Scroll down and select ‘Less secure app access’
  4. Turn on access

This will solve my “SMTP Error: Could not authenticate” in PHPMailer error.

answered Apr 29, 2020 at 13:07

ruwanmadhusanka's user avatar

ruwanmadhusankaruwanmadhusanka

8312 gold badges8 silver badges15 bronze badges

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)

answered Aug 18, 2019 at 14:06

user3809638's user avatar

0

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)

answered Apr 13, 2022 at 9:49

Gosforth's user avatar

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)

answered Jan 29, 2015 at 21:35

anu's user avatar

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]

answered Feb 10, 2016 at 7:17

Jathin Prasad's user avatar

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.

cSteusloff's user avatar

cSteusloff

2,4677 gold badges28 silver badges51 bronze badges

answered Dec 14, 2017 at 11:47

Joshua Mutinda's user avatar

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.

answered Apr 12, 2018 at 7:24

Ravindra Miyani's user avatar

No doubt, PHPMailer is a powerful and popular email-sending library for PHP that enables developers to send emails via SMTP or PHP’s mail() function with ease.

SMTP or Simple Mail Transfer Protocol is an essential component of email communication that allows users to send and receive emails. SMTP authentication is a crucial security feature that ensures only authorized users can send emails through a server.

However, there may be instances when PHPMailer fails to work due to issues such as misconfigured SMTP settings or compatibility problems with the server. When this happens, it may trigger an SMTP error: could not authenticate the message and prevents users from sending emails.

In this article, we will figure out the major possible reasons for this error and the best troubleshooting to fix them.

Let us get started!


Read: 🚩 Free SMTP Servers for Sending Emails – 2023


What does “SMTP Error: Could not authenticate” mean?

“SMTP Error: Could Not Authenticate” error occurs when the email client cannot verify the user’s login credentials. It is a common authentication error that can be caused by incorrect login credentials or configuration errors.

Other common SMTP authentication errors include:

  • SMTP Error: Authentication Failed
  • SMTP Error: Username and Password not accepted
  • SMTP Error: Authentication method not supported

Read: 🚩 SMTP Port 25, 465, 587, 2525: Which Port Should I Use?


What are the Causes of “SMTP Error: Could not authenticate”?

1. Incorrect Authentication Error: Incorrect login credentials are the most common cause of SMTP authentication errors. Users must ensure that they enter the correct username and password for their email account.

2. Authentication protocol not supported: Email clients and servers support different authentication protocols. If the email client does not support the authentication protocol used by the server, authentication will fail.

3. Incorrect SMTP port and SMTP host: Sometimes, users in a hurry, enter the wrong mail server details in the mail application. In addition to that a slight mistake in the hostname or inactive mail server can also result in an SMTP error: could not authenticate.

4. Misconfigured SMTP encryption settings: When it comes to secure email transmission, SMTP with encryption is the top choice for most users. The two encryption protocols that are commonly used for this purpose are SSL and TLS. However, it’s important to keep in mind that some mail servers may lack SSL/TLS support or have an expired SSL certificate, resulting in an SMTP error.

5. Password has expired: It’s not uncommon for servers to be set up to auto-expire passwords, and sometimes app maintainers may forget to update them on time. This can lead to a situation where the mail server is unable to validate the password when the application tries to connect. Result in “SMTP error: could not authenticate”.

6. Firewall or antivirus software blocking authentication: A firewall or antivirus software can block authentication, preventing the email client from communicating with the server. Users can temporarily disable these programs to test if they are causing the issue.


Here are some of the best ways you can fix your SMTP error: could not Authenticate, check them out in detail.

1. Verify login credentials

To ensure successful email transmission, You must verify that the correct username and password are included in the mail script. Also, you should ensure that you have entered the correct username and password for the email account.

Additionally, for default email accounts, the full username ([email protected]) must be provided in the application. If the password was recently changed, it should also be updated in the email application.

2. Enable authentication protocol supported by email client and server

If the email client does not support the authentication protocol used by the server, You should switch to a supported protocol. Common authentication protocols include SMTP-AUTH, POP3, and IMAP.

3. Temporarily disable the firewall or antivirus software

You can temporarily disable the firewall or antivirus software to test if they are causing the authentication issue. If the issue persists, You can contact the software provider for further assistance.

4. Verify email client or server configuration

Users should verify that their email client and server settings are correctly configured. Incorrect settings can cause SMTP authentication errors.

Here are some steps to verify email client or server configuration:

1. Double-check the email client settings to ensure that the correct incoming and outgoing mail servers have been specified.

2. Verify that the email client is using the correct port settings for incoming and outgoing mail.

For example, if you choose Gmail as your mail server (Gmail SMTP server), the hostname you should use is “smtp.gmail.com.” In addition to the default SMTP port 25, some mail servers use custom ports like 587 to avoid spam. Moreover, certain mail servers may only permit emails via SSL port 465.

To verify the configuration of your email client or server, you can also use a few helpful commands. For example, to check the DNS connectivity of the mail server, you can use the “dig” command, like so:

dig mail.example.com

You can also identify the correct SMTP port and confirm connectivity to the SMTP port using the “telnet” command:

telnet example.com 25

Finally, make sure to double-check the SMTP settings in your application to ensure that the correct SMTP host and port are being used.

3. Confirm that the username and password for the email account are correct and properly entered into the email client settings.

4. Test the email account settings by sending a test email to ensure that the account is configured correctly.


Free SMTP Server for Testing: RUN test


5. Check for any error messages or warnings that may appear during the configuration process or when sending test emails.

6. Consult the email client or server documentation or support resources for further assistance if any issues persist.

5. Properly configure SMTP encryption

It’s crucial to ensure that ‘mod_ssl’ and ‘openssl’ are correctly configured on the server for SSL to work effectively.

You must verify the mail server’s SSL certificate’s validity using the following command:

openssl s_client -connect mail.example.com:25 -starttls smtp

Therefore, the solution is to configure SSL correctly for the server or remove the encryption utilized in the SMTP settings.

6. Reconfigure apps as per Google standards

Google does not compromise on security and enforces strict security restrictions. Therefore, if any app fails to meet Google’s security standards, it may be blocked from accessing Google services. This is because such apps have the potential to break easily and can be vulnerable to security breaches.

If you try to authenticate to the Google server, you might encounter the “SMTP error: could not authenticate” error. This is because Google treats login credentials as insecure.

The best way to avoid this issue is to reconfigure your app according to Google’s standards. If you wish to use your own custom settings without adhering to Google’s standards, you will need to loosen the security restrictions.

To do this,

  • Sign in to your Google admin console.
  • Click on Security and scroll down to click on the “Turn on access(not recommended) link.
  • Now a Less secure App access page will open.
  • Toggle to turn on “Allow less secure apps” and you are done.

Less Secure App Access

Less Secure App Access
Allow Less Secure Apps
Allow Less Secure Apps

Conclusion

SMTP authentication errors can be frustrating and can prevent users from sending emails. By understanding common SMTP authentication errors and their causes, You can quickly diagnose and fix these issues.

By verifying login credentials, enabling supported authentication protocols, temporarily disabling the firewall or antivirus software, and verifying email client or server configuration, You can quickly fix SMTP authentication errors and ensure smooth email communication.


Read: 🚩 How To Resolve WordPress Not Sending Emails Issue? [2023]


Frequently Asked Questions

How do I fix SMTP authentication error?

To fix the SMTP authentication error, Follow the methods given below:
1. Verify login credentials
2. Enable authentication protocol supported by email client and server
3. Temporarily disable the firewall or antivirus software
4. Verify email client or server configuration
5. Properly configure SMTP encryption
6. Reconfigure apps as per Google standards

How do I fix SMTP authentication error in Gmail?

To fix the SMTP authentication error in Gmail, do the following:
1. Verify login credentials.
2. Ensure enabling two-factor authentication
3. Logout from other Google accounts
4. Turn on “Allow less secure apps” in your google account security settings.

What does SMTP error could not authenticate mean?

SMTP error: could not authenticate means that the email server was unable to authenticate the login credentials provided by the user. In simpler terms, the email client or application is not able to verify the username and password combination with the mail server, resulting in a failure to send or receive emails. This error message usually indicates that there is a problem with the authentication process, such as an incorrect password, an expired password, or a misconfigured SMTP server.


PHPMailer is a great tool to send emails safely and easily using SMTP authentication.

But, sometimes this may fail due to incompatible server settings or incorrect SMTP configuration.

smtp error: could not authenticate” is one such problem reported by website owners when using PHPmailer to send emails.

At Bobcares, we resolve such email errors as part of our Outsourced Technical Support for web hosting providers.

Today, let’s see the top 5 reasons for this error and how our engineers fix it.

What is this “smtp error: could not authenticate” error?

Simply put, this error says:  “You try to connect to SMTP server, but it can’t authenticate you“.

So, it could mean,

  • The PHP application was able to connect to SMTP server, but the authentication failed.
  • Application was not able to connect to the SMTP server.

What’s wrong here? Let’s have a quick look.

Causes and Fixes for “smtp error: could not authenticate” error in phpmailer

1) Wrong SMTP authentication details

Each mail server uses an authentication system to validate users before they can connect and send emails.

When you send an email from your script, the mail server attempts to identify the user with the account’s username and password.

If this authentication fails, the mail server rejects the connection and users receive the error “smtp error: could not authenticate“.

Solution

We’ll ensure that correct username and password are given in the mail script.

In case of default email accounts, the full username(user@domain.com) should be given in the application.

Also, if the password was recently modified, it should be updated in the email application.

2) Wrong SMTP port and SMTP Host

Users should enter the mail server details in the “$mail->Host” field of the email application.

For example, if you use Gmail as your mail server, the hostname should be “smtp.gmail.com“.

Sometimes, a typo in the hostname or an inactive mail server result in this error.

Similarly, for port numbers, the default SMTP port is 25, but some mail servers use custom ports, such as 587, to avoid spam.

Also, some mail servers will be configured to allow emails only via SSL port 465.

It is also possible that some email providers restrict access to their SMTP port using firewall rules.

Incorrect port entry in SMTP settings or firewall restrictions may cause email delivery errors.

Solution

We’ll ensure the DNS connectivity of the mail server with the command.

dig mail.domain.com

Also, to identify the correct SMTP port and confirm connectivity to the SMTP port, we use the command:

telnet domain.com 25

We cross-check the SMTP settings in the application and make sure that correct SMTP host and port is used.

If we find any firewall restrictions, the IP should be whitelisted in the firewall.

3) SMTP encryption settings

For secure email transmission, most users prefer SMTP with encryption. SSL and TLS are the 2 encryption protocols used.

But, on some mail servers, SSL/TLS support may not be enabled or the existing SSL certificate may have expired.

What if users specify encryption in their application? Result is “smtp error: could not authenticate” error.

Solution

Our Support Engineers ensure that Apache and PHP are properly configured on the server with ‘mod_ssl‘ and ‘openssl‘ so that SSL can work on the server.

We’ll also verify the validity of mail server’s SSL certificate using the command:

openssl s_client -connect mail.example.com:25 -starttls smtp

So, the solution here is to properly configure SSL for the server or remove the encryption used in the SMTP settings.

4) Google blocks insecure access

Gmail enforces strict security restrictions.

If an app doesn’t meet these security standards, it may block access because these apps are easier to break into.

Users who authenticate to Gmail server receive the error “smtp error: could not authenticate” because Google considers username and password login as insecure.

Solution

Ideally, we reconfigure the app so that it meets the Google standards. If this is not possible, we’ll help website owners to loosen the security restrictions using the below steps.

  • Sign in to the Google admin console.
  • Go to Security > Basic settings.
  • Go to Less Secure Apps.
  • Turn on Allow less secure apps.

phpmailer smtp error: could not authenticate

Allow less secure apps in gmail account

5) Expired Password

This can happen once in a while.

Some servers are set to auto expire passwords and app maintainers forget to update them in time.

When the application tries to connect, the mail server could not validate the password.

Result is “smtp error: could not authenticate” error.

Solution

This usually happens when the account owner missed the notification email about password expiry.

In such cases, we reset the password and also update it in the email application.

We also make sure that the notification email is set correctly, and in some cases, we remove the password expiration set for the mailbox.

Conclusion

smtp error: could not authenticate” is a common error when users send emails via PHPMailer using SMTP authentication. This error occurs when the application can’t establish an SMTP connection to the mail server. Today, we’ve seen the top 5 causes of this error and how our Support Engineers fix them.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

SEE SERVER ADMIN PLANS

var google_conversion_label = «owonCMyG5nEQ0aD71QM»;

Please check these things before submitting your issue:

  • Make sure you’re using the latest version of PHPMailer
  • Check that your problem is not dealt with in the troubleshooting guide, especially if you’re having problems connecting to Gmail or GoDaddy
  • Include sufficient code to reproduce your problem
  • If you’re having an SMTP issue, include the debug output generated with SMTPDebug = 2 set
  • If you have a question about how to use PHPMailer (rather than reporting a bug in it), tag a question on Stack Overflow with phpmailer, but search first!

Problem description

When i trying send message from smtp.gmail.com, with ssl, or tls, or different ports, doesnt matter, it’s throw exception to me.
I have Allowed less secure apps in gmail, and i visit captcha confirmation

Code to reproduce

$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->CharSet = "UTF-8";

$mail->Username = "example@gmail.com";
$mail->Password = "*******";
$mail->setFrom("example@gmail.com", "Alex");
$mail->Subject = "Тест, отправка письма";
$mail->msgHTML("Message");
$mail->addAddress("example@mail.ru");

if (!$mail->send()) {
    $mail->ErrorInfo;
} else {
    echo "123";
}

Debug output

2017-10-23 19:44:18 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP q24sm1694776lff.48 - gsmtp

2017-10-23 19:44:18 CLIENT -> SERVER: EHLO *my_server*

2017-10-23 19:44:18 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [*my_server*]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8

2017-10-23 19:44:18 CLIENT -> SERVER: AUTH LOGIN

2017-10-23 19:44:18 SERVER -> CLIENT: 334 VXNlcm5hbWU6

2017-10-23 19:44:18 CLIENT -> SERVER: YXJldm9sdXRpb25wcm9qZWN0QGdtYWlsLmNvbQ==

2017-10-23 19:44:18 SERVER -> CLIENT: 334 UGFzc3dvcmQ6

2017-10-23 19:44:18 CLIENT -> SERVER: cmV2b2x1dGlvbjEyMw==

2017-10-23 19:44:18 SERVER -> CLIENT: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbtI534-5.7.14 qNIYrbZEk6FWx5rHcj6iG24Wnch4-cJAfM8uoUKM9jkHSMq_RaHs_A6dTS2Os70c6MUtaD534-5.7.14 5g_o5siaKUXvyrEugwt0FU-QBcUwp5HHAFfiHmTpuRu57eG1k4pH6sv5fXSQn2dgrZDEtn534-5.7.14 29ptACC7djB5Hv_usdmgN5yckn6u5Q79E3JqMGpS8nN7ZagN2geB2kO3-jkRJN8grPtIVK534-5.7.14 rAXLtSmpqVqRunISlK0V0x80FTYLY> Please log in via your web browser and534-5.7.14 then try again.534-5.7.14  Learn more at534 5.7.14  https://support.google.com/mail/answer/78754 q24sm1694776lff.48 - gsmtp

2017-10-23 19:44:18 SMTP ERROR: Password command failed: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbtI534-5.7.14 qNIYrbZEk6FWx5rHcj6iG24Wnch4-cJAfM8uoUKM9jkHSMq_RaHs_A6dTS2Os70c6MUtaD534-5.7.14 5g_o5siaKUXvyrEugwt0FU-QBcUwp5HHAFfiHmTpuRu57eG1k4pH6sv5fXSQn2dgrZDEtn534-5.7.14 29ptACC7djB5Hv_usdmgN5yckn6u5Q79E3JqMGpS8nN7ZagN2geB2kO3-jkRJN8grPtIVK534-5.7.14 rAXLtSmpqVqRunISlK0V0x80FTYLY> Please log in via your web browser and534-5.7.14 then try again.534-5.7.14  Learn more at534 5.7.14  https://support.google.com/mail/answer/78754 q24sm1694776lff.48 - gsmtp

SMTP Error: Could not authenticate.

2017-10-23 19:44:18 CLIENT -> SERVER: QUIT

2017-10-23 19:44:19 SERVER -> CLIENT: 221 2.0.0 closing connection q24sm1694776lff.48 - gsmtp

SMTP Error: Could not authenticate.

  • Ошибка подключения к signalr
  • Ошибка подключения к rdp серверу
  • Ошибка подключения к psn
  • Ошибка подключения к openid провайдеру 1c
  • Ошибка подключения к my kaspersky как убрать