Bobcares

PHPMailer authtype – Here’s how to choose the right one

by | Mar 5, 2019

PHPMailer gains its popularity due to its advanced features in sending emails. It supports methods to authorize users, send attachments and more.

But, choosing PHPMailer authtype depends on the specific mail server configuration. Often, using wrong auth types can result in email errors.

At Bobcares, we solve many PHPMailer errors as part of our Server Management Services.

Today, we’ll see how our Support Engineers help customers choose the right PHPMailer auth type and fix common errors with it.

 

What is PHPMailer?

In simple words, PHPMailer is a program that helps to send mails from web applications.

Unlike normal PHP mail function, it supports security methods like message encryption, authentication, etc. Additionally, PHPMailer can send attachments and even HTML messages. That’s why, popular applications like WordPress, Joomla, etc. include PHPMailer in their mail programs. For example, wp_mail function  in WordPress relies on the PHPMailer class to send email through PHP’s mail function.

Again, one of the most effective feature of PHPMailer is that it supports several authentication mechanisms. These auth methods avoid the sending of unknown emails. Thus, it can greatly help on reducing spamming.

That’s why, our Support Engineers usually recommend shared server owners to setup mail programs that support authentication methods. Essentially, properly updated PHPMailer packages does the mail sending jobs beautifully.

 

Overview of PHPMailer authtypes

As we already saw, in shared servers with too many accounts, anonymity can be an advantage to email spammers. Fortunately, using the proper authtype makes emails from PHPMailer more accountable. It helps to allow only emails from valid users.

Now, let’s see the top auth types that PHPMailer supports.

The authtype options in PHPMailer are CRAM-MD5, LOGIN, PLAIN, XOAUTH2.  If there is no specific option set in the PHPMailer config file, it tries each of these mechanisms. In case of wrong logins, when one auth type fails, others also will result in error.

We’ll now check what each of these auth options do.

 

PLAIN

In auth PLAIN mechanism, the server converts the email user name and password to base64 encoded credentials.  And, anybody can easily decrypt this data. Therefore, this allows even the attacker to decrypt it and misuse the data. This is why, our Dedicated Engineers always secure the connection with SSL/TLS while having a session with the SMTP server.

 

LOGIN

Similarly, LOGIN is another method of authentication in servers. Here, after sending the AUTH LOGIN command, the mail server asks for username and password by sending BASE64 encoded questions to the client. Then, client sends the encrypted username and password. Again, this method becomes insecure without proper mail settings.

 

CRAM-MD5

To overcome the drawbacks of AUTH and PLAIN, there comes an authentication mechanism with the name CRAM-MD5. This uses a complex method to send messages between the server and client. Also, the response send by the server will be valid only for one time. Thus, it helps to avoid hacker using it again.

 

XOAUTH2

XOAUTH2 is mainly used in Google authentication. Mainly, this method relies on the league/oauth2-client library. So, for customers who wish to use Gmail servers in their PHPMailer config, we preset the server with necessary modules.

 

However, in real time environment, mail server may not support all auth types. Therefore, it is really necessary to choose the authtype in PHPMailer as per the app requirement.

In general, to know about the exact auth types supported by the mail server, our Support Engineers do a telnet to port 25 of the mail server. The output shows up as below.

220 domain.com ESMTP MailCleaner (Community Edition 2018.12) Tue, 05 Mar 2019 13:47:32 +0530
EHLO domain.com
250-domain.com Hello domain.com [172.17.252.159]
250-SIZE 104857600
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP

For instance, this mail server supports PLAIN, LOGIN mechanisms.

And, our Support Engineers set PHPMailer authtype to PLAIN using the following option in configuration file.

/* Set AuthType to PLAIN. */
$mail->AuthType = 'PLAIN';

Common errors with PHPMailer authtype and fixes

However, from our experience in managing PHP applications, we often see application errors due to bad selection of PHPMailer authtype. Let’s now see how our Support Engineers diagnose and fix them.

1. Firewall restrictions

Recently, one of our customers reported problems with using Gmail server in his PHPMailer configuration. The error showed up as:

2018-12-19 08:25:29 Connection failed. Error #2: stream_socket_client():
unable to connect to smtp.gmail.co.za:587 (Connection timed out)
[/home/xxx/public_html/PHPMailer-master/src/SMTP.php line 326]
2018-12-19 08:25:29 SMTP ERROR: Failed to connect to server: Connection
timed out (110) SMTP connect() failed.

On checking the reason for the error, we first confirmed that the authtype is properly set to XOAUTH2. But, we could see that the outgoing mail port 587 was closed. Here, our Support Engineers modified the firewall to allow mail traffic on port 587 to Gmail servers. And, the mail started working.

 

2. AUTH not accepted from server

Similarly, there can be problems when PHPMailer uses an auth type that is not supported by the mail server. Here, we fix the problem by editing the PHPMailer configuration to use the correct authtype. On secure mail servers, we set the authentication type as PLAIN and mail starts working.

[Need help to fix PHPMailer errors? We can help you.]

 

Conclusion

In short, PHPMailer adds more security to emails by allowing different authtypes. Today, we saw the different auth mechanisms in PHPMailer and how our Support Engineers help customers to choose the right PHPMailer authtype.

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.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

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

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

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

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

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