WPForms Blog

WordPress Tutorials, Tips, and Resources to Help Grow Your Business

How to Send WordPress Emails With Mailgun

by Courtney Robertson on Nov 21, 2016

Have you noticed that you’re not receiving WordPress contact form notifications? You might be wondering why WPForms isn’t sending you emails when someone fills out your forms, or why you aren’t seeing any WordPress notifications.

In this tutorial, we’ll walk you through how to fix email delivery issues by sending WordPress emails with Mailgun.

Why Email Notifications Don’t Work

Maybe you’ve noticed that WordPress isn’t sending you email notifications because form entries are piling up in your WordPress dashboard, or frustrated visitors start to reach out to you using social media or other methods.

The most common reason for missing these emails is due to your WordPress hosting server. Usually it isn’t configured to use the PHP mail() function, which WordPress uses by default to send emails generated by WordPress or any contact plugin like WPForms.

Thankfully, you can work around this issue by using SMTP.

SMTP (Simple Mail Transfer Protocol) is the industry standard for sending emails. Unlike PHP mail function, SMTP uses proper authentication which increases email deliverability. That’s why we recommend using SMTP to send emails in WordPress.

In this article we’ll show one of the many SMTP services we recommend: Mailgun. If you want to learn about the pros and cons of other ways to fix this problem, visit How to Fix WordPress Contact Form Not Sending Email With SMTP.

How to Fix Your Form Notifications

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, though beyond that it’s a paid service. But that’s more than enough for most small websites.

Let’s get started setting up your site to send WordPress emails with Mailgun.

1. Sign up for a Mailgun account

First you need to signup on the Mailgun website. Mailgun will prompt you to add a domain right when you sign up, though this can also be accessed by logging into Mailgun and going to Domains, then clicking the Add New Domain button.

Add new domain to Mailgun

Next, you’ll need to enter a subdomain of your website’s domain name.

What does that 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 like blog.example.com).

In this case, the subdomain we’ll create will be used by Mailgun to send emails.

We’ll create the actual subdomain in the next step. For now, you can just enter a subdomain such as mail.yourwebsite.com. (It doesn’t really matter what you name it, but using “mail” makes it clear what its purpose is.)

Add a domain to Mailgun

Keep the Mailgun page open in your browser as we continue with the next step.

2. Verify 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.

If you’re not sure where to find your site’s DNS settings or feel unsure about making changes, please contact your hosting provider.

First, you’ll need to open your 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.

Mailgun Domains page

Once you’re in your DNS settings, you should see an option to add a new record. Mailgun will require you to enter two TXT records, which they also list on their setup page. Here’s an example of what this section should look like if you’re on Mailgun’s site:

Mailgun DNS records for sending

The first record you’ll need to add is for SPF, or Sender Policy Framework, which is the way that most email providers will verify your domain:

  • Type: TXT
  • Value: “v=spf1 include:mailgun.org ~all”

You may also see a TTL, or Time To Live, field for the record. This indicates how long this DNS record should be cached before it gets refreshed. You can leave this blank to allow the default TTL value to be used.

Instead of SPF, many other email providers will use DKIM. DKIM serves the same purpose as SPF but uses cryptographic methods. To make it possible for these services to also verify your domain you’ll need to add a second TXT record. However, the value of this record will be specific to your Mailgun account.

The next step is to add MX, or Mail Exchanger, records. MX records are what note how email should be handled. This is recommended to ensure successful delivery unless you have a specific reason not to do so.

If you are already using MX records to point to an email provider, such as Google Apps, skip this step to avoid email delivery issues from a DNS conflict.

Mailgun’s MX records are the same for everyone:

First MX record:

  • Type: MX
  • Priority: 10
  • Value: “mxa.mailgun.org”

Second MX record:

  • Type: MX
  • Priority: 10
  • Value: “mxb.mailgun.org”

If you’d like to use Mailgun to track events and statistics for messages, you’ll can choose to add one more DNS record: a CNAME. You can read more about the type of tracking Mailgun offers in their documentation here, and the custom CNAME record is available on your Mailgun account below the MX records.

Once you’ve completed these steps, your DNS settings are good to go.

5. Check 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 by visiting Domains page in your Mailgun account.

Once Mailgun can verify the DNS changes you made, it will show active status next to your domain name.

View active domain on Mailgun

However, you can skip to the next step while you wait for this verification to complete.

6. Configure WordPress to Send Emails

Now that you’ve set up your DNS, you can prepare your WordPress site to start using Mailgun for sending emails.

The first thing you need to do is install and activate the Mailgun for WordPress plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit Settings » Mailgun to configure plugin settings.

Add Mailgun API to WordPress

By default, Mailgun sends emails by using a method called “HTTP API,” as you can see in the first option. This is the recommended method so you can leave it as the default. But if for some reason it doesn’t work on your website, then you can switch to SMTP and see if that works.

You will need your Mailgun API keys. Simply login to Mailgun dashboard and click on your domain name. Mailgun will show your SMTP credentials as well as API key.

Mailgun API Key

You need to copy and paste those keys into plugin settings and click on the save changes button.

After storing your settings you can click on the test configuration button. Mailgun will test your settings and will show you a success message.

That’s it! You have successfully setup your site to send WordPress emails with Mailgun. Now your form notifications will reach your email inbox.

Looking for more email notification tips? You might also want to check out our guide on how to send users confirmation emails from WordPress forms. This is a great way to reassure visitors that their message has been received, and prevent them from sending duplicates.

Don’t have WPForms yet? What are you waiting for? Get started with the most powerful WordPress forms plugin today.

If you like this article, then please follow us on Facebook and Twitter for more free WordPress tutorials.


  1. Hi,
    I’ve completed step 5 above (my sub-domain is showing active on Mailgun). Now I have a question regarding step 6 – Configuring WordPress to send emails.
    Should I install the Mailgun Plugin on my main domain or onto the sub-domain that I have created for Mailgun?

    1. Hi Peter! You can go ahead and install the Mailgun plugin on your main domain, where your WordPress installation is. There’s no need to have anything on the subdomain you created for sending mail – it’s just used for your email, not anything else. Please do get in touch with support if you need any help setting up your WPForms notifications 🙂

  2. Hi there,

    I’m having trouble setting up Mailgun on WordPress, having already verified the subdomain. I’m on GoDaddy hosting and from searching around, it appears that the problem I’m having is common with them.

    Having gone through the steps above I’m getting the below message when I test the configuration:

    Mailgun SMTP Test Failure; status “SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

    I’m knowledge of WordPress is very basic and I have no coding knowldge. My reason for installing Mailgun is to be able to send automatic email notifications when forms are completed on the wordpress site.

    Any help much appreciated!

  3. Hi,

    I followed this right to the end and everything seems to be working except when I go to test the configuration, I get the following error message:
    “Mailgun HTTP API Test Failure; status “null””
    Any thoughts?


    1. Hi Alex,

      The next step I’d recommend is to contact your hosting provider. We’ve found that some hosts block SMTPs by default, but usually a quick call or chat can resolve this.

      If that doesn’t do the trick, could you please contact us in support? From there, we’ll be able to collect more details and help you troubleshoot further if needed 🙂

  4. Hi, I get a Mailgun HTTP API Test Success; status “Success” status on my test, however wp is not using these settings for some reason. Any ideas what might be wrong?

    1. Hi Niklas,

      If your SMTP test email is successful but your form’s notification emails still aren’t getting delivered, usually this is because of the form’s notification settings (in the form builder under Settings > Notifications). The most common issue is the From Email — this must be set to the email you set up the SMTP with.

      If that doesn’t seem to be the issue, could you please contact us in support? From there we’ll be able to collect more details and see what else might be going on.

      Thanks! 🙂

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.