Need help?

Our experts have had an average response time of 13.14 minutes in February 2024 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

How to fix “smtp error: could not authenticate” in PHPMailer

by | Nov 16, 2018

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

12 Comments

  1. vam

    i have tried alll these but still same error

    Reply
  2. Name *Anabela

    Apareceu este erro: SMTP ERROR: Failed to connect to server: Connection timed out (110)SMTP connect() failed. https;//github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

    Reply
    • Mahmud

      Message could not be sent.
      Mailer Error: SMTP connect() failed.

      Reply
      • Sijin George

        Hello Mahmud,
        The error appears to be due to the wrong PHPMailer settings. Have you double-checked the Host settings? If you need further assistance, we’ll be happy to talk to you on chat (click on the icon at right-bottom).

        Reply
        • Adarsh

          hi, there can you help me out as well since i have the same error

          Reply
          • Arya MA

            Hi Adarsh,

            We will be happy to help you. You can initiate a chat by clicking on the icon at right-bottom.

  3. MOstafa

    Thanks. My Problem Has Solved.

    Reply
  4. Yahucoder

    Hello, Have done everything, but the thing is this. When i connect to my personal modem, am able to send mail, but immediatley i connect to my office lan, i keep getting the error message “Object { status: “failed”, response: “Something is wrong: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting” }”

    Reply
    • Sijin George

      Hello,
      It should be some restrictions in your office LAN for SMTP port. If you still have errors and need help, we’ll be happy to talk to you on chat (click on the icon at right-bottom).

      Reply
  5. Firoz khan

    i have tried all the above steps but still am getting the error..\
    Message could not be sent. Mailer Error: SMTP Error: Could not authenticate

    Reply
    • Arya MA

      Hi Firoz,

      We are happy to help you. To contact our support team, please initiate a chat from the icon at right-bottom.

      Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF