PHPMailer smtp error could not authenticate







PHPMailer is a code library to send (transport) emails safely and easily via PHP code from a web server.
It is a powerful tool meant for sending emails safely and easily using SMTP authentication.

In some cases, it might fail to function due to incompatible server settings or incorrect SMTP configuration and thus lead to error such as "smtp error: could not authenticate".
This is generally experienced in the process of using PHPmailer to send emails.

Here at Ibmi Media, we regularly help our Customers to fix email errors as part of our Outsourced Support Services.
In this context, we shall have a look at different causes of this error and how to fix it.

Nature of PHPMailer error "smtp error: could not authenticate" ?

When this error occurs, you will see and error message such as this;
You try to connect to SMTP server, but it can’t authenticate you

What this signifies is that;
i. The PHP application was able to connect to SMTP server, but the authentication failed.
ii. Application was not able to connect to the SMTP server.

The main reasons and fixes for PHPMailer error "smtp error: could not authenticate" ?

1. Incorrect 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
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
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
Ensure that Apache and PHP are properly configured on the server with 'mod_ssl' and 'openssl' so that SSL can work on the server.
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
Some email providers such as 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 following steps;
i. Sign in to the Google admin console.
ii. Go to Security > Basic settings.
iii. Go to Less Secure Apps.
iv. Turn on Allow less secure apps.

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.

[Need an urgent fix to email server issues? We are available to help you today]


Conclusion

This article will guide you on how to fix PHPMailer error "smtp error: could not authenticate" which generally occurs when the application can’t establish an SMTP connection to the mail server. This is experienced when users send emails via PHPMailer using SMTP authentication.


For Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on LinuxAPT.com

Also for Tech related tips, Visit forum.outsourcepath.com



Related Posts






Focus on your business, not your servers.

Click Here to Learn More






Recent Post