How to Set Up Mailgun in WordPress

How to Set Up Mailgun in WordPress (Step by Step)

Summarize:ChatGPTPerplexity

A WordPress site that can’t send email loses password resets, receipts, and every form notification. Mailgun fixes that, and it’s one of the more reliable ways to do it.

But Mailgun won’t send a thing until you’ve verified a sending subdomain in your DNS.

In this post, you’ll learn how to connect Mailgun to WordPress using the WP Mail SMTP Setup Wizard, which fills most of those fields for you.

You’ll also learn which of Mailgun’s 3 API keys to use, and what to check when the test email fails.

Let’s get started.

Fix Your WordPress Emails Now

What Is Mailgun, and Why Use It for WordPress Email?

Mailgun is an email delivery service that routes your site’s mail through its own authenticated servers rather than your web host’s.

That matters because WordPress has no mail server of its own. It hands every message to PHP’s mail() function, which most hosts throttle, block, or leave unauthenticated. Inbox providers then treat those messages as suspicious.

Here’s what you get with Mailgun:

  • Authenticated sending. Your domain’s DNS records prove the mail is really from you.
  • Delivery logs. You can see whether a message was accepted, deferred, or bounced.
  • A free tier. Free accounts send up to 100 emails per day. Adding a credit card removes that daily limit.

Mailgun does ask for more setup than most mailers. You need DNS access, and you need to verify a subdomain before anything sends. That’s the trade-off for its deliverability.

Note: Want a fuller breakdown of features and pricing before you commit? Read our Mailgun review.

How to Create a Mailgun Account

Sign up on Mailgun’s website, then complete both verification steps.

The Mailgun signup form

After the signup form, Mailgun emails you a confirmation link. Click Verify your email address to continue.

Mailgun account verification email

Next, Mailgun asks you to verify a phone number. Both checks help keep spammers off its sending IPs, which is part of why its delivery rates hold up.

Mailgun phone number verification screen

How to Add Your Sending Domain in Mailgun

From your Mailgun dashboard, go to Sending » Domains, then click Add New Domain.

The Sending Domains menu in Mailgun

The Add New Domain button in Mailgun

Why Does Mailgun Need a Subdomain?

Mailgun asks for a subdomain so your sending reputation stays separate from your main domain.

A subdomain replaces the “www” in your address, like mg.example.com. Mailgun only uses it to send mail. It never shows up on your site.

Enter something clear, such as mg.example.com. I’d suggest avoiding mail.example.com, as it might be in use by your web host.

Entering a sending subdomain in Mailgun

Which Mailgun Region Should You Choose?

Pick EU only if your site is hosted in the European Union. Everyone else leaves the default US option.

The Mailgun domain region setting

Warning: Whatever you pick here has to match the Region setting in WP Mail SMTP later. A mismatch is one of the most common reasons Mailgun setups fail silently.

Now open the Advanced settings (DKIM) dropdown. Choose 2048, which creates a longer DKIM key and adds a layer of spam protection.

Mailgun advanced DKIM settings set to 2048

Click Add Domain to finish. Keep this tab open, because you’ll need the DNS values next.

The Add Domain button in Mailgun

How to Verify Your Domain With DNS Records

Mailgun verifies your domain when you add its TXT and MX records to your DNS.

Open your site’s DNS settings first. Mailgun links to setup guides for common providers right on the page where you added the domain.

Mailgun's DNS provider links

Add the 2 TXT records exactly as Mailgun shows them. Copy the values carefully, since a single wrong character stops verification.

Adding a Mailgun TXT record in a DNS panel

Then add the MX records the same way. Add them for the subdomain you created, not your main domain.

Adding Mailgun MX records in a DNS panel

Note: Some hosts append your domain to whatever you type. If yours does, enter just mg instead of mg.example.com for the hostname. If you’d like a walkthrough for your provider, see our guide to DNS email configuration.

If your DNS panel offers a TTL field, set it to one day (86400 seconds).

Mailgun also shows a CNAME record. You can skip it, since it only matters for tracking, not sending.

Back in Mailgun, click Verify DNS settings to check your work.

The Verify DNS settings button in Mailgun

Once the records propagate, your domain shows as active. However, DNS record propagation can take 24 to 48 hours, so don’t wait on it. Carry on with the next step.

An active domain status in Mailgun

Fix Your WordPress Emails Now

Where to Find Your Mailgun API Key

Click the circle with your initials in the top right of Mailgun, then select API Security.

The API Security option in the Mailgun account menu

Which of Mailgun’s 3 API Keys Should You Use?

Use the Mailgun API key. Not the Verification Public key, and not the HTTP Webhook Signing key.

That’s the single most common mistake in a Mailgun setup. All 3 keys sit on the same page, and picking the Verification Public key causes deliverability problems that are hard to trace.

Scroll to the Mailgun API keys section and click Create API key.

The Create API key button in Mailgun

Add a description you’ll recognize later, then click Create Key.

Adding a description to a new Mailgun API key

Copy the key with the copy icon and store it somewhere safe.

Copying a new Mailgun API key

Important: Mailgun shows the key once. If you lose it, you’ll have to create a new one.

How to Connect Mailgun to WordPress Using WP Mail SMTP

The Setup Wizard walks you through the plugin side in 5 steps and fills in the settings as you go.

Step 1: Install WP Mail SMTP

If you want to use Mailgun in WordPress, you need WP Mail SMTP. It’s the best SMTP plugin for WordPress, making the whole process super easy.

To install the WP Mail SMTP plugin, log in to your WordPress admin area and navigate to Plugins » Add Plugin. Once here, type “wp mail smtp” in to the search bar and

Search WP Mail SMTP

Then click Install Now next to the WP Mail SMTP plugin.

Install WP Mail SMTP plugin

Once the installation completes, the button changes to “Activate”. Click on it to activate the plugin.

Activate plugin

You should be directed to the Setup Wizard after activating the plugin.

Step 2: Launch the Setup Wizard

Alternatively, you can access the setup wizard by navigating to WP Mail SMTP » Settings. Once here, click Launch Setup Wizard below the Primary Connection section.

The Launch Setup Wizard button in WP Mail SMTP settings

Note: The wizard only configures your Primary Connection. Additional connections must be set up on the plugin’s settings page.

Click Let’s Get Started to begin.

The Let's Get Started button in the WP Mail SMTP Setup Wizard

Step 3: Select Mailgun as Your Mailer

Click Mailgun in the mailer grid, then click Save and Continue.

WP Mail SMTP Setup Wizard mailer selection screen with Mailgun selected

How to Enter Your Mailgun Settings

The wizard now shows only the fields Mailgun needs. There are 5, in this order:

  1. Mailgun API Key. Paste the key you copied earlier.
  2. Domain Name. The subdomain you created in Mailgun, such as mg.example.com.
  3. Region. Match what you chose in Mailgun. Outside the EU, that’s US.
  4. From Name. The sender name on your site’s emails. Turn on Force From Name to apply it across the board.
  5. From Email. An address on the domain you verified, like [email protected]. Turn on Force From Email so every email uses it.

WP Mail SMTP Setup Wizard Mailgun settings step showing the API Key, Domain Name, and Region fields

Pro Tip: Use an address connected to a real inbox for the From Email. Bounce notices and replies go there.

Click Save and Continue when you’re done.

Step 4: Enable Email Features

Leave Improved Email Deliverability and Email Error Tracking on. They’re both on by default and can’t be turned off.

The rest are worth a look:

  • Detailed Email Logs. A record of every email your site sends.
  • Complete Email Reports. Deliverability stats over time. Needs logs enabled.
  • Weekly Email Summary. A weekly digest of your sending. Needs logs enabled.
  • Instant Email Alerts. Notifies you by email, SMS, Slack, or webhook when a send fails.

Selecting email features in the WP Mail SMTP Setup Wizard

Note: Email logging needs a paid WP Mail SMTP license.

If you enabled logs, the next screen asks what to store. Pick your options and click Save and Continue.

Configuring email log options in the Setup Wizard

Lastly, paste your license key and click Verify License Key. Or click Skip this Step to do it later.

Entering a license key in the WP Mail SMTP Setup Wizard

How to Send a Test Email

The wizard sends one for you automatically at the end.

If it works, you’ll see “Congrats, you’ve successfully set up WP Mail SMTP!” Click Finish Setup and you’re done.

The WP Mail SMTP Setup Wizard success screen

You can send more tests any time from WP Mail SMTP » Tools » Email Test.

What to Do if Your Mailgun Test Email Fails

Click Start Troubleshooting on the wizard’s error screen to see the actual error message.

The WP Mail SMTP Setup Wizard troubleshooting screen

In my experience, 4 causes cover nearly every failure:

What went wrongHow to fix it
DNS hasn’t propagatedWait up to 48 hours, then click Verify DNS settings in Mailgun again
Region mismatchMake the plugin’s Region match your Mailgun domain’s region
Wrong API keyUse the Mailgun API key, not the Verification Public key
Domain mismatchThe plugin’s Domain Name must be the subdomain, not your root domain

Older accounts have a fifth cause: a missing key- prefix on the API key.

Still stuck? Our guide to WP Mail SMTP not sending test emails covers the less common errors.

Pro Tip: Add a Backup Connection with a second mailer like SendLayer. If Mailgun ever fails, WP Mail SMTP sends through the backup instead of dropping the email.

Frequently Asked Questions

Is Mailgun free for WordPress?

Yes, up to a point. Free accounts send up to 100 emails per day. Adding a credit card removes that daily limit, and you still won’t be charged on the free tier.

Do I need a plugin to use Mailgun with WordPress?

Yes. WordPress can’t talk to Mailgun’s API on its own. SMTP plugins like WP Mail SMTP handle the connection and route every wp_mail() call through Mailgun.

Why is Mailgun not sending my WordPress emails?

Check your domain’s verification status in Mailgun first. After that, check 3 things: a region mismatch, the wrong API key, or a Domain Name set to your root domain.

Do I have to use a subdomain with Mailgun?

It’s what Mailgun recommends, and it’s the safer choice. A subdomain keeps your sending reputation separate from your main domain, so a deliverability problem doesn’t follow your whole site.

Should I choose the US or EU region?

Choose EU if your site is hosted in the European Union. Otherwise choose US. The setting has to match in both Mailgun and WP Mail SMTP.

Next, Set Up SPF, DKIM, and DMARC Records

Now that Mailgun is sending your email, I’d tighten up your domain’s authentication next. Our guide to SPF, DKIM, and DMARC records explains what each record does and walks you through adding them. Getting all 3 right is what keeps your mail out of the spam folder. It also builds directly on the DNS work you just finished.

Fix Your WordPress Emails Now

Ready to fix your emails? Get started today with the best WordPress SMTP plugin. If you don’t have the time to fix your emails, you can get full White Glove Setup assistance as an extra purchase, and there’s a 14-day money-back guarantee for all paid plans.

If this article helped you out, please follow us on Facebook and Twitter for more WordPress tips and tutorials.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPForms is funded, why it matters, and how you can support us.

David Ozokoye

David is a technical writer at WP Mail SMTP. He tests and documents new features and updates to the WP Mail SMTP plugin. Away from the computer, he enjoys playing video games and roller skating. Learn More

Try our Free WP Mail SMTP plugin

Use your favorite SMTP provider to reliably send your WordPress emails.