How To Setup an SMTP Mailer in WordPress
Email delivery is getting more challenging, WordPress by default uses what is called a PHP mailer. Basically lines of code generate the email on your server and sends it off. And SMTP mailer will use an email account that it logs into and send the email from there.
Have you noticed emails to a Gmail account are not being delivered?
In the last few years Gmail heavily blocks emails send from PHP mailers, Why? Because its the easier way for scammers to spoof an email pretending to imitate a business. To ensure proper delivery, especially to Gmail accounts you should use an SMTP mailer and have SPF records and DMARC records set up.
Step 1: Install an SMTP plugin
There are loads of SMTP mailers for WordPress. They all do the same thing, login to an email account to send emails, even Gravity Forms now has their own built in SMTP mailer.
My go to is WP Mail SMTP which you can install from the WordPress plugin repository https://wordpress.org/plugins/wp-mail-smtp/ if you like the plugin, you can also opt for the pro version which has reports, logging and a good email delivery diagnosis tool: https://wpmailsmtp.com/.
Step 2: Checking the current configuration
Once you install WP Mail SMTP it will show the current mailer being used on WordPress, you should se “Default” which indicated the PHP mailer is being used.
We are going to select “Other SMTP” and as you and there is some simple information we need to get it working. I will run through what each of them are and then how to obtain them:
- SMTP Host: This is the server where email is sent from. Example mail.mywebsite.com.au
- Encryption: TLS is the industry standard, all email services and hosting services should support it. However on the rare occasion that it does fail we can just use SSL.
- SMTP Port: This is set by your hosting provider, usually is either port 465 or 587.
- Authentication: 100% this is needed.
- SMTP Username: This is usually the email address.
- SMTP Password: This is usually the password for the email account.
Step 3: Getting your SMTP mail settings:
If your website is hosted on an cPanel hosting service its quite straight forward. Login to cPanel and under the Email heading click on “Email Accounts”. If you only have the system email account, you will need to create one that you will be using to send emails from your website.
On the right hand side the email account you would like to use, click on “Connect Devices”
On this screen, you should now see the SSL/TLS settings for your email accounts SMTP.
What we need to take note of here is:
- Username – Usually the account email address
- Outgoing Server – Where the mail will be sent from
- SMTP Port – The port used to send email
- Password – This is not shown in cPanel so if you do not know the password you may need to reset it.
Step 4: Configuring WP Mail SMTP
Head back over to WordPress and from WP Mail SMTP head to the “Settings” page.
The first setting to enter is the “From Email”, always make sure this matches the email account to improve deliverability. If its set to a different email address it will likely bounce as your email server may not have permission to send from that address.
Be sure to also click the checkbox “Force From Email”
Now scroll down to the SMTP settings. Enter your SMTP Host (the outgoing server setting from cPanel). For encryption, test out TLS first which will use port 587 by default. Make sure Authentication is enabled and enter your SMTP Username (account email address) and the password.
Step 5: Testing your settings
Next, save your settings the then scroll up to Email Test from the MP Mail SMTP menu. Put in any email address to test if you can receive emails from the website via SMTP.
You should see a page like the above, and check your inbox to see if you received the email. On the same email test page, WP Mail SMTP will also check your DNS records to see if your SPF and DMARC are set correctly. This one I am setting up is for a test and this article we can ignore the DMARC notification.
What if my SMTP Email test failed?
The most common failure I see is the when the email test hangs or times out like in the screenshot below:
Usually this means your host does not support TLS or the port is incorrect.
What you can try to do is:
- Change the SMTP from 587 to 465.
- If that does not work, change the encryption method from TLS to SSL.
- If that does not work, disable the “Auto TLS” setting.
Any other simpler errors such as a host timeout or authentication error likely indicate the username or password is incorrect.