How to Setup Mailgun to Send Email with WordPress

Last Updated on January 2, 2023 by 7 Comments

Editorial Note: We may earn a commission when you visit links on our website.
How to Setup Mailgun to Send Email with WordPress
Blog / WordPress / How to Setup Mailgun to Send Email with WordPress

WordPress enables you to send a broad range of transactional emails right out of the box. These include messages for user registration, password resets, and much more. However, the emails don’t always arrive as intended, and while it’s not WordPress’ fault, it’s definitely a problem you need to solve – potentially using a service such as Mailgun.

In this article, we’ll talk about what transactional emails are and how you can use Mailgun to make sure your WordPress messages get to their destination.

Let’s talk about emails!

What Are Transactional Emails?

The emails you send to your users can be broken down into two broad categories:

  1. Marketing emails. For this type of message, you need to get consent from users before you add them to your mailing list.
  2. Transactional emails. These are automated emails related to business or account ‘transactions’ for your users. As such, they don’t need to subscribe to get transactional emails.

There are dozens of examples of transactional emails, such as “Thank you” messages:

A thank you email.

Other notable examples include registration confirmations, password reset messages, and more. What sets this type of message apart is that WordPress can send them automatically, without the need for an Email Service Provider (ESP).

There are a lot of reasons why you might want to use an ESP over WordPress’ built-in email functionality, though. Let’s talk about what those are.

Why Use Mailgun Over WordPress’ Built-In Email Functionality?

The primary issue with using WordPress for transactional emails is deliverability. A lot of email providers are very aggressive when it comes to filtering incoming messages and those that come from your site can fall in their crosshairs. This is the reason why so many sites ask that you check your spam filter if you don’t receive an email.

However, this doesn’t happen because your website or hosting provider is doing something wrong. The problem lies in the other users you’re sharing the server with, some of who may be abusing transactional emails.

A lot of web servers aren’t configured to handle email deliveries, either. ESPs such as Mailgun take over transactional email duties for your website, ensuring you get a much higher deliverability rate:

The Mailgun homepage.

However, the advantages of using an ESP go a lot further. For example, Mailgun also offers email analytics, tracking, and in-depth logs. Plus, if something goes wrong with the service, you can always ask an expert for support instead of troubleshooting it yourself.

Mailgun isn’t the only game in the ESP market. However, it’s one of our favorite tools due to its generous free trial and flexible pricing. In the next section, we’ll show you precisely how it works.

How to Set Up Mailgun to Send Email with WordPress (3 Steps)

For this tutorial, we’re going to show you how to set up a Mailgun account. Then we’ll configure it to take over your WordPress website’s transactional email duties, all in three short steps. Let’s get to work!

Step 1: Create a Mailgun Account

As usual, the first step is the simplest. Go to Mailgun’s website and select the option to sign up for a new account. You’ll need to fill out some basic contact information and add a credit card to your file to get access to Mailgun’s full set of features:

Adding your payment information for Mailgun.

Keep in mind that Mailgun offers a three-month trial period before it starts charging you for emails. At this point, you pay $0.80 per 1000 emails on the basic Pay As You Go plan.

You could also forego adding payment information while you set Mailgun up to work with WordPress. However, if you choose this option, you’ll be limited to a maximum of five recipients.

Once you fill out the entire form, you can wrap up the signup process and get access to the Mailgun dashboard:

The Mailgun dashboard.

The next step is to configure Mailgun to work with your WordPress website’s domain.

Step 2: Configure Your Domain Name to Work With Mailgun

Once you’re in, head to the Domains tab in Mailgun and click on the Add New Domain button:

Adding a new domain to Mailgun.

On the next page, Mailgun will explain that it’s best if you set up a subdomain to manage email sending. Using a subdomain works best for troubleshooting purposes and it makes it easier to update DNS records without causing issues (more of which in a second.)

For example, if you own the johndoe.com domain, you can use mail.johndoe.com for transactional messages:

Choosing what domain to add to Mailgun.

By default, Mailgun will use either a US or EU server to send emails as well as set up encryption for your messages. Leave the default settings for now, and add the domain you want. Note that you need to use a domain you own, as you’ll need to make some changes to its Domain Name Settings (DNS).

Next up, you’ll get a list of TXT, MX, and CNAME DNS records you need to add so Mailgun can work:

Mailgun sending records.

This process will vary depending on what registrar you use. For example, with Namecheap, you need to go into the Advanced DNS tab for the domain you want to use with Mailgun and modify the records therein:

Configuring Namecheap's DNS records.

If you’re not sure how to update your domain’s DNS records, we recommend you consult with your registrar’s support service. Once your new records are set, you can use the Verify DNS Settings button within Mailgun’s options for the specified domain:

Verifying your DNS records.

DNS updates can take a while to propagate, so don’t worry if Mailgun can’t verify the changes right away. Once it’s able to verify your settings the next step is to configure WordPress to use the service.

Step 3: Set Up and Configure the Mailgun Plugin

Mailgun offers an official plugin you can use to connect the ESP with your WordPress website, although you’ll need to check that it works with your version of WordPress. To find it, go your dashboard and navigate to Plugins > Add New, then look for the Mailgun for WordPress plugin:

The Mailgun for WordPress plugin.

Install and activate the plugin then go to the new Settings > Mailgun tab. Here make sure the Use HTTP API setting is set to yes to maximize deliverability, then enter the Mailgun domain you set up earlier below:

Configuring Mailgun to work with WordPress.

You’ll also need to enter your Mailgun API key. You can find this within the Mailgun Settings tab:

Finding your Mailgun API key.

Return to WordPress, paste the API key and move on down to the From Address and From Name fields. Here you can configure the address that will show up as the sender for your transactional emails as well as its associated name:

Configuring your email sender settings.

Save the plugin’s settings and that’s it! Now Mailgun will take over transactional email duties for WordPress, ensuring your messages don’t make it into your users’ spam folders.

Conclusion

Mailgun is one of the best ESPs you can use for your WordPress website. Their flexible pricing model means you’ll likely only spend a handful of dollars a year on transactional emails. If you have hundreds or thousands of users, your budget will likely be higher, although you’ll still get great service regardless.

Setting up Mailgun to work with WordPress takes only three simple steps:

  1. Create a Mailgun account.
  2. Configure your domain name to work with Mailgun.
  3. Set up and configure the Mailgun plugin.

Do you have any questions about how to use Mailgun with WordPress? Let’s go over them in the comments section below!

Article thumbnail image by Belozersky / shutterstock.com

Divi

Want To Build Better WordPress Websites? Start Here! 👇

Take the first step towards a better website.

Get Started
Divi
Premade Layouts

Check Out These Related Posts

MonsterInsights Review 2024: Worth It for Site Analytics?

MonsterInsights Review 2024: Worth It for Site Analytics?

Updated on April 16, 2024 in WordPress

Do you want to integrate Google Analytics (GA) on your WordPress website easily? Look no further than MonsterInsights. It offers invaluable insights into your site’s traffic, user behavior, and content engagement. As the leading Google Analytics plugin for WordPress, MonsterInsights empowers...

View Full Post

7 Comments

  1. Hi,
    Thanks for sharing the process. It’s seems pretty easy now to use ESP like Mailgun . And the difference you told also clear my mind why should I choose ESP rather than conventional Mail smtp service.

  2. Why would anyone install mailgun plugin that is not updated in quite a while. A better and updated plugin is WP Mail SMTP

  3. You are promoting a plugin that displays the following message on WordPress.org:
    “This plugin hasn’t been tested with the latest 3 major releases of WordPress. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.”

  4. Why would anyone want to use WP Mail SMTP in addition to Mailgun? The entire aim of Mailgun is so that you don’t need WP Mail SMTP – or SMTP mail at all, for that matter!

    • Wait, what? I must have misunderstood what you wrote. You need an SMTP plugin (I use WP MAIL SMTP) to connect Mailgun service with your website.

    • WP Mail SMTP gives you the ability to connect to Mailgun via API so you do not have to send via SMTP. Since they keep their plugin updated I’ve moved away from using the Mailgun plugin.

      I’ve been using MailGun for several years to send email form WordPress websites. It’s worked very well.

  5. I just want to know that, is this plugin is compatible with any WordPress theme?

Leave A Reply

Comments are reviewed and must adhere to our comments policy.

Get Started With Divi