Chat with us, powered by LiveChat

This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

How to Set up and Configure WordPress SMTP on Server & Using Plugin

August 30, 2019

11 Min Read
wordpress smtp
Reading Time: 11 minutes

One of the most common ways of sending out emails in PHP projects is through the mail() function. However, according to the official documentation, PHP mail() is not suitable for bulk email projects. Here is what it states:

It is worth noting that the mail() function is not suitable for larger volumes of email in a loop. This function opens and closes an SMTP socket for each email, which is not very efficient.

As you can see, the PHP itself discourages the use of mail() function for sending out a huge volume of emails. This encourages PHP developers to explore other options.

However, by default, WordPress also uses PHP mail() function to send out the transactional emails such as user registration and forgot password emails.

Why WordPress Emails Get Marked as Spam?

You might observe the emails from your WordPress website landing in Spam/Junk folders. In most of the cases, it happens if you are hosted on a shared WordPress hosting environment where every user shares the same server IP address. Now, if any ONE of the users sharing the IP block is marked as Spam, the entire server will be marked as spam.

Thus, no matter what, every email originating from this server will be detected and marked as spam by the email service providers such as Gmail, Outlook, Yahoo, etc.

If your customers/subscribers are not receiving emails, ask them to check out the Spam/Junk folder. If that’s the case, the most likely causes are that the server IP is marked as spam or the server is not sending out the emails. Another important cause is that the respective port is blocked by the hosting provider.

If your WordPress emails are marked as spam and/or the subscribers aren’t receiving the email, this guide is specifically for you.

Use SMTP for WordPress Emails

SMTP stands for Simple Mail Transfer Protocol. It is a service used to send out emails from a server to the final recipients or to intermediary servers.

A number of WordPress email plugins allow you to configure and send all outgoing emails via an SMTP service provider. Alternatively, you can set up SMTP on the server. This will prevent your emails from landing into the Spam/Junk folder of the recipients.

As far as WordPress is concerned, I believe that SMTP is a good alternative to the PHP mail function. Once configured properly, all WordPress sending emails will be sent via SMTP server ensuring that the email appears to originate from an authorized source.

Let’s start by configuring WordPress email settings on a server first. Later, I will set up SMTP via WP Mail SMTP (a WordPress SMTP plugin).

Setup SMTP Service on Server

In many cases, users often have several websites on a single server and want to use the same SMTP service for all of them. In this case, the ideal solution is to set up SMTP on a server instead of setting it up on each WordPress site separately.

If you are a Cloudways customer and want to send mail in WordPress without a plugin, then login to your account, and click on the Servers tab located in the left corner of the top bar and get into your server. In the left menu, click the SMTP tab.

SMTP on Server

In the SMTP screen, you will see two options:

  1. Your Own SMTP: Choose this, if you are planning to use a third-party service like Gmail SMTP, Mailgun, Sendgrid, etc.
  2. Elastic Email: We are partnered with Elastic email, an SMTP service provider, choose this option if you want to setup SMTP easily.

I will use Your Own SMTP to select an SMTP provider from the available options. Note that you will be asked for the username and password of the selected SMTP provider.

SMTP Service Provider

In this guide, I will cover Mailgun and SendGrid (from the available options) and Gmail SMTP (via the Other option).

Configure Mailgun SMTP for WordPress

Mailgun is an email automation service owned by Rackspace. Mailgun is considered as one of the best WordPress SMTP providers as it allows you to send, receive, track and store emails easily. Mailgun is a popular choice for sending out newsletters, notifications, or any other communication item you want to distribute among your subscribers.

Another advantage of Mailgun is that it allows you to send 10,000 emails every month for FREE. If you need to send out more than 10K emails, they have an excellent pricing model that fits all budgets.

To use Mailgun, you need to have an account with Mailgun. Once your account is live, log in to your account, and visit the Mailgun dashboard. Since I want to use my domain name for sending emails, I will add my domain name to Mailgun.

From the top menu bar, go to Domains and click Add New Domain. Note that, you may need to add a credit card to add a custom domain name.

Add Domain Mailgun

Once added, Mailgun recommends verifying the domain name to ensure smooth operations. Here is an excellent guide on how you can verify your domain for Mailgun. If you have any questions, ping your DNS register for help.

Verifying the domain is important mainly because:

  • Verified domains are not subjected to the limit of 300 outgoing emails per day.
  • No more Sent via Mailgun.org footer text in your emails.
  • Mailgun is less suspicious of traffic that is being sent by verified domains.

I assume that you have followed the guide and verified your domain name. To get SMTP credentials, navigate to Sending (1) -> Domain Settings (2), select the domain name (3) from the top drop-down menu, and then click SMTP credentials (4).

Mailgun SMTP Credentials

Copy email address (5) and paste in the Cloudways platform. To get the password (6), click on the Reset Password button. This will generate a new password that you can now copy and paste in the Cloudways platform.

Mailgun SMTP on Server

To update DNS records, navigate to Sending -> Domains and go to your domain name and follow the instructions.

Mailgun Domains

Configure SendGrid SMTP for WordPress

Just like Mailgun, SendGrid is a cloud-based SMTP service provider that allows you to send and receive bulk emails. SendGrid is ideal for marketing campaigns and transactional emails without worrying about the emails being marked as Spam.

Here’s a trivia that highlights the position of SendGrid among the popular SMTP providers: Over 58,000 paying customers use SendGrid to send more than 35 billion emails every month.

SendGrid also offers a free-to-try plan known as Essentials that includes 40,000 emails (free for the first 30 days) and 100 free outgoing emails/day forever.

First things first, you need to create an account with SendGrid.

Important Note: Sign up with the same email address you’d like to set as the From email. The two email addresses should match in later steps.

I assume, you have created an account with SendGrid and are logged into the SendGrid dashboard. In the left pane, open the drop-down menu and go to the Setup Guide. Click the Start button beside Integrate using our Web API or SMTP Relay.

send grid

Choose SMTP Relay from the available options.

Integration

On the next screen, SendGrid will ask you to name your API key. Name it anything you want, and click Create Key.

Copy this key and paste it in the Password field in the Cloudways platform. Set the username as apikey and click the Save button.

SendGrid SMTP

Get back to the SendGrid dashboard, check the highlighted checkbox (see the following screenshot), and click the Next: Verify Integration button.

On the next screen, you will get a success message.

Verify Domain & Email Links

Again, just like Mailgun, SendGrid also recommends verifying the domain and Email links to ensure proper delivery of the emails. In SendGrid, this process is known as Whitelabeling.

To help out the users, SendGrid has excellent guides on Whitelabeling Domain and Email Links.

By following the above process, your server will start using SendGrid SMTP for outgoing emails.

Configure Gmail SMTP for WordPress

What follows is a detailed step-by-step guide to set up Gmail SMTP on your hosting server.

Prerequisites

Before setting up Gmail SMTP, read these precautions carefully.

  • If you have enabled Two-Factor Authentication on your Gmail account, you need to generate a special password and note it down as it will be required for different password fields.
  • If you have not enabled Two-Factor Authentication, you just need to allow access to less secure apps from here. Just click the Turn On button.
  • You need to authorize your server to access your Gmail account. If you have merged more than one account on Gmail, login with the main account, open this link, and click the Continue button.

So without further delay, let’s set up Gmail SMTP on the server.

Come back to the Cloudways platform and you can see that Gmail SMTP is not in the available options. To work around this, select the Other option to setup Gmail SMTP on the server and enter the details as follows:

  • Host: smtp.gmail.com
  • Port: 587
  • Username: Your Gmail Email Address
  • Password: Your Gmail Password (or App Generated Password)

Gmail SMTP

In fact, by following the above steps, you can configure any third party SMTP service provider that is not on the list.

Do Not Forget To Read This Note:

By setting up SMTP on a server, all applications will use these SMTP settings. Make sure you change the FROM address for individual applications.

Go to your target application, navigate to the Application Settings and check out FROM ADDRESS. Enter an email address that will be displayed as a “From Address” for every transactional (SMTP)/outgoing email.

WordPress SMTP From Address

If you have multiple servers, repeat the above step for each server.

WordPress SMTP Plugin

If you do not want to setup SMTP on your server, you can use a WordPress email plugin and configure it for sending out WordPress emails.

You need to choose which WordPress SMTP plugin you want to use. We have a detailed guide on Post SMTP mailer, and this guide is focused on WP Mail SMTP plugin.

After you have installed and activated the plugin, you will see a new label WP Mail SMTP under the Settings menu.

There are just three steps to set up the WP Mail SMTP plugin. Let’s cover them by one!

Enter Email Address

Generally, businesses prefer to use the official email address for all WordPress sending emails. Thus, it is very important to make sure that this field DOESN’T have the default address (usually wordpress@domain.com).

Enter the email address and the name you wish to use for your outgoing emails.

Note that when it comes to setting the FROM email address and name,  several plugins might conflict with the WP Mail SMTP plugin. To avoid this, check the Force From Email and Force From Name checkboxes.

WP Mail SMTP Email Services

Set up Mailer

The next step is to set up an SMTP service provider. In this example, I will explain how to set up:

  • MailGun SMTP for WordPress
  • SendGrid SMTP for WordPress
  • Gmail SMTP for WordPress

If your SMTP provider is not on the above list, don’t worry. The steps for setting up your prefered SMTP provider are generally similar to what I am going to mention below:

Mailgun SMTP for WordPress

Follow these steps to get the API Key and paste it into the WP Mail SMTP plugin. To enter the correct domain name, log in to Mailgun account and copy the exact domain name.

Don’t forget to click Save Settings at the bottom of the page. Now, navigate to the Email Test tab at the top and send a test email to your email address. You should get an email like:

SendGrid SMTP for WordPress

Follow these steps to get the API Key and paste in WP Mail SMTP plugin and then click the Save Settings.

Sendgrid API key

Go to the Email Test tab, enter the email address where you want to receive the test email. And, you should get the test email, similar to the following:

sendgrid

Configure Gmail SMTP on WordPress

Unlike Mailgun and Sendgrid, you need to put in extra efforts to set up Gmail SMTP using WP Mail SMTP. You need to get a Client ID and Client Secret.

Read these precautions carefully.

  • If you have enabled two-factor authentication on your Gmail account. You need to generate a special password and note it down as it will be required for different password fields. Follow Sign in using App Passwords to generate an app password.
  • If you have not enabled two-factor authentication, you just need to allow access to less secure apps. Just toggle the Turn On button.
  • You need to authorize your server to access your Gmail account. If you have merged more than one account on Gmail → log in with the main account → allow access to your Google account and click on the Continue button.

The next step involves Gmail configuration. Log in to the Google Developer Console with your Gmail ID, create a project and enable the Gmail API for your WordPress site.

create project

Click Go to credentials to get the credentials required for setting up your Gmail SMTP on WordPress.

Enabling API

Set the options as shown below:

gmail credentials

Click What credentials do I need? button to proceed to the final step for getting your Client ID.

  • For the Name field, provide the name of your choice
  • Under Authorized JavaScript origins, enter your site URL
  • For Authorized redirect URL, copy the URL from WP Mail SMTP plugin settings page.

adding client id

create client ID

Now click Create client ID and on the next page, check your email address and the Product name to verify your details. Next, click Continue.

credentials

Click I’ll do this later and on the next screen, click Edit to reveal Client ID and Client Secret.

Copy these and go back to the WP Mail SMTP plugin dashboard and paste it under Gmail settings.

Click the Save Settings button. Next, authorize the WP Mail SMTP plugin to use your Gmail account to send out WordPress emails.

authorize

During the process, you may get a warning because the domain name does not have an SSL certificate. To avoid this, you need to add an SSL certificate to your WordPress site.

warning

Once allowed, navigate to the Email Test tab at the top to test your newly configured Gmail SMTP email.

Allow WordPress Site to Use Google Console

Send Test Email

Once successfully installed and configured, it is time to test the email sending process. For this, enter an email address and hit the Send Test button.

send test email

Here’s how the test email will look like:

email receiving

And that’s it! But before I move further, let me warn you that Gmail (the free version) restricts you to only 500 emails or 500 recipients per day.

If you want more, try out the premium SMTP providers that offer plans with better limits.

If you have any queries or get stuck at any step, feel free to comment below. I would like to help you out!

Share your opinion in the comment section. COMMENT NOW

Share This Article

Start Growing with Cloudways Today!

We never compromise on performance, security, and support.

Mustaasam Saleem

Mustaasam is the WordPress Community Manager at Cloudways - A Managed WordPress Hosting Platform, where he actively works and loves sharing his knowledge with the WordPress Community. When he is not working, you can find him playing squash with his friends, or defending in Football, and listening to music. You can email him at mustaasam.saleem@cloudways.com

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

BFCM 2019