Are you looking for a super reliable email delivery solution in WordPress that can work with your custom email address? Mailgun is a service specifically designed to help your emails get delivered successfully. In this tutorial, we’ll walk you through how to fix email delivery issues in WordPress using Mailgun with WP Mail SMTP.
- What is Mailgun?
- Signing Up for a Mailgun Account
- Verifying Your Domain
- Checking your Mailgun Verification Status
- Configuring WordPress to Send Emails
- Sending a Test Email
What is Mailgun?
Mailgun is a popular email service provider that allows website owners to send large quantities of emails. You can send your first 10,000 emails for free every month (or 100 emails per hour), though beyond that it’s a paid service. But that’s more than enough emails for most small websites.
While the setup for Mailgun is can require more time than some other mailer options, these steps are what allow it to be such a reliable email delivery service.
Another important consideration when choosing a mailer is what you’d like your From Email to be. The From Email is the email address that emails appear to be sent from (the “sender”). Mailgun generally works fine with any From Email, however we recommend using a domain-specific email address (ie firstname.lastname@example.org) for most reliable email delivery.
Note: Would you like our team to do this setup for you? With White Glove Setup, we’ll do all configuration and testing for the Mailgun mailer on your site.
1. Signing Up for a Mailgun Account
To get started in this setup process, you’ll need to have a Mailgun account.
If you don’t already have an account with Mailgun, go ahead and sign up for an account on Mailgun’s website.
Note: As an added verification step, Mailgun will require that you enter credit card information to set up an account (even if using a free account). For more information, please see Mailgun’s signup page.
After completing the short signup form, you’ll have a couple of additional verification steps to complete. Multiple levels of verification is what allows Mailgun to better ensure high standards of email deliverability for all of their users.
First, you should receive an email to verify your Mailgun account. You’ll need to click the link within this email in order to start the verification process.
After clicking the verification link in this email, you’ll be asked to enter a mobile number to receive a text verification code.
Once you’ve completed these steps, you should automatically be logged into your Mailgun account.
Now that you’re logged in, you should be seeing your Mailgun dashboard. When you’re ready, click on Domains in the left menu.
On the Domains page, you’ll need to click the Add New Domain button.
Note: If you don’t see a button to add a new domain, this likely means that you haven’t yet entered a credit card. Mailgun requires all accounts (even free accounts) to enter a credit card before you can continue.
Next, you’ll need to enter a subdomain of your website’s domain name.
What does this mean, exactly? A subdomain replaces the “www” part of your website’s address; for example: “subdomain.yourwebsite.com.” Subdomains can be used to add separate sections or directories to your website (like how some sites have their blogs on a subdomain such as blog.example.com).
In this case, the subdomain will be used by Mailgun to send emails and will not be visible on your site at all.
We’ll create the actual subdomain a little later. For now, you can just enter a subdomain such as mail.yourwebsite.com or mg.yourwebsite.com. It doesn’t really matter what you name it, but using “mail” or “mg” makes it more clear what the purpose of this subdomain is.
Next, you’ll need to choose between two regions: US or EU. If your site is hosted in the European Union, then go ahead and choose EU. If your site is hosted anywhere outside of the European Union, then leave the default US option.
Last, we recommend keeping the Create DKIM Authority box checked for an extra mode of spam protection.
We also recommend selecting the 2048 option, which creates a longer DKIM key.
As we continue into the next step, be sure to keep this tab or window open as we’ll return to this page later.
2. Verifying Your Domain
As a way of both protecting site owners and their visitors, some SMTP services like Mailgun require that you verify your domain by adding records to your site’s DNS. You can find more information on the benefits of verifying your domain in Mailgun’s guide.
First, you’ll need to open your site’s DNS settings. If you’re not sure how to find these, Mailgun will provide you with some helpful links shown on their setup page when you’re adding a new domain.
Note: If you’re not sure where to find your site’s DNS settings or feel unsure about making changes, please contact your site’s hosting provider before making adjustments.
Or for more details on modifying a site’s DNS, you can check out WPBeginner’s tutorial on DNS settings.
Once your DNS settings are open, you should see an option to add a new record.
To make it possible for Mailgun to verify your domain, you’ll need to add two TXT records to your site’s DNS. Be sure to copy them carefully, as you’ll need the exact values from your Mailgun account for the verification to work.
Note: If your DNS is managed by GoDaddy, then you will slightly adjust the Hostname shown in Mailgun. When entering the Hostname into your GoDaddy DNS, you’ll need to remove your normal domain. For example, instead of entering mg.yourdomain.com for the first TXT record’s Hostname, you would only enter mg
In your site’s DNS settings you may also see a TTL (Time To Live) field for the record. If you’re provided with a way to change this, we recommend setting the TTL to one day (or 86400 seconds, depending on the units your DNS uses).
Once you’ve added both TXT records, you’ll need to add MX records in exactly the same way. Just please remember that you must do this for the subdomain you created — not for the main domain.
Now that you’ve added both TXT and MX records, your DNS settings are all set.
Note: Mailgun will also show you a CNAME record, however you can ignore this as it’s not relevant when using Mailgun only to send emails.
3. Checking your Mailgun Verification Status
Now Mailgun will need to verify that your domain has proper DNS records. This verification can take a while (sometimes 24-48 hours) because DNS records may take some time to update.
You can check the status of your domain verification at any time by visiting the Domains page in your Mailgun account. Once Mailgun can verify the DNS changes you made, it will show an active status next to your domain name.
However, there’s no need to wait on this just yet! You can move ahead to the next step while you wait for this verification to complete. Just be sure to keep this tab or window open, as we’ll need it a little later.
4. Configuring WordPress to Send Emails
Now that you’ve set up your DNS, you can prepare your WordPress site to start using Mailgun with WP Mail SMTP for sending emails.
After installing and activating this plugin, you need to navigate to WP Mail SMTP » Settings to configure plugin settings.
At the top of this page, you can set the From Email and From Name. By default, these will fill with your site’s admin email and site name.
For the From Email, you can use any valid email address. However, for best results we recommend using a domain-specific email address (ie email@example.com).
You can also choose to check the box labeled Force From Email. If you’d like the From Email to be the same site-wide, this option will save you the trouble of editing the email settings throughout your site (in all form emails, etc).
You may add any From Name you’d like, and you can also choose to Force From Name to apply this setting site-wide.
Next, in the Mailer field you’ll need to select the Mailgun option.
We also recommend checking the optional Return Path checkbox to Set the return-path to match the From Email. With this enabled, you’ll be emailed if any messages bounce as a result of issues with the recipient’s email.
Now that you’ve selected Mailgun as your mailer, a new Mailgun section will appear. Here, you’ll need to enter API and domain information.
Even if your domain is still waiting to be verified, Mailgun will provide this information. You may even have automatically received an email containing your API key, otherwise you’ll need to return to the tab or window with your Mailgun domain details.
In the upper right corner of your Mailgun account, you’ll need to click on the small circle with your initials. Then, select the Security option.
This will take you to a page that includes your API key. You’ll need to click the eye icon to view your full API key.
Once you’ve copied the text for the full key (including
key- at the start), return to the WP Mail SMTP settings and paste it into the API Key field.
Then for the Domain Name, enter the subdomain you created in Mailgun (for example, mg.yourdomain.com).
Last, you’ll need to check the Region setting. This should match what you set up in Mailgun (anyone outside of the European union should select the US option).
Once this information is complete, go ahead and save your settings.
5. Sending a Test Email
Note: Before proceeding with this step, make sure that the verification process from Step 3 is complete. This may take a while, so it’s possible you’ll need to come back to this later.
Once your domain is verified and your settings have been added to WP Mail SMTP, it’s important to send a test email to ensure that everything is working properly.
To do this, you’ll need to go to WP Mail SMTP » Settings and then click on the Email Test tab.
On this tab, you can enter any email address that you have access to and click the Send Email button.
After sending the email, you should see a success message.
If you check the inbox for that email address, you should receive the email for this test.
It’s also a good idea to fill out a couple of test submissions for your forms after completing this setup to check that emails deliver successfully.
That’s it! You have successfully set up your WordPress site to send authenticated emails with Mailgun.
Next, would you like to set up email logging to make sure you have a backup of all emails sent from your site? Be sure to check out our tutorial on using WP Mail SMTP to keep a log of all emails your site sends out.