### [How to Set Up Mailgun in WordPress (Step by Step)](https://wpmailsmtp.com/how-to-set-up-mailgun-in-wordpress-step-by-step/)

**Published:** September 4, 2026
**Author:** David Ozokoye

**Excerpt:** Is your WordPress site dropping password resets and form notifications?

Mailgun sends your email through authenticated servers instead of your host's. The WP Mail SMTP Setup Wizard handles the plugin side for you.

You'll verify a sending subdomain, add your DNS records, and pick the right one of Mailgun's 3 API keys.

**Content:**

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.

- [How to Create a Mailgun Account](#aioseo-how-to-create-a-mailgun-account)
- [How to Add Your Sending Domain in Mailgun](#aioseo-how-to-add-your-sending-domain-in-mailgun)
- [How to Verify Your Domain With DNS Records](#aioseo-how-to-verify-your-domain-with-dns-records)
- [Where to Find Your Mailgun API Key](#aioseo-where-to-find-your-mailgun-api-key)
- [How to Connect Mailgun to WordPress Using WP Mail SMTP](#aioseo-how-to-connect-mailgun-to-wordpress-with-the-setup-wizard)
- [What to Do if Your Mailgun Test Email Fails](#aioseo-what-to-do-if-your-mailgun-test-email-fails)

[Fix Your WordPress Emails Now](https://wpmailsmtp.com/pricing/)

## 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](https://wpmailsmtp.com/mailgun-review/).

## How to Create a Mailgun Account

Sign up on [Mailgun’s website](https://www.mailgun.com/), then complete both verification steps.

![The Mailgun signup form](https://wpmailsmtp.com/wp-content/uploads/2022/10/Sign-up-for-a-Mailgun-account-1-1024x679.png)After the signup form, Mailgun emails you a confirmation link. Click **Verify your email address** to continue.

![Mailgun account verification email](https://wpmailsmtp.com/wp-content/uploads/2022/10/Verify-Mailgun-Account-1024x473.png)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](https://wpmailsmtp.com/wp-content/uploads/2022/10/Verify-your-phone-number-on-Mailgun-1024x633.png)## 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](https://wpmailsmtp.com/wp-content/uploads/2023/03/sending-domain-smtp-1024x439.png)![The Add New Domain button in Mailgun](https://wpmailsmtp.com/wp-content/uploads/2022/10/Add-New-Domain-1024x295.png)### 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](https://wpmailsmtp.com/wp-content/uploads/2022/10/Enter-domain-name-and-region-1024x544.png)### 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](https://wpmailsmtp.com/wp-content/uploads/2022/10/Domain-region-settings-1024x262.png)**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](https://wpmailsmtp.com/wp-content/uploads/2022/10/Mailgun-advanced-settings-for-DKIM-1024x378.png)Click **Add Domain** to finish. Keep this tab open, because you’ll need the DNS values next.

![The Add Domain button in Mailgun](https://wpmailsmtp.com/wp-content/uploads/2022/10/Click-on-add-domain-1024x378.png)## 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](https://wpmailsmtp.com/wp-content/uploads/2022/10/Common-provider-links-to-setup-DNS-1-1024x729.png)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](https://wpmailsmtp.com/wp-content/uploads/2022/10/Add-Mailgun-TXT-record-to-hosting-provider-1024x633.png)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](https://wpmailsmtp.com/wp-content/uploads/2022/10/Add-MX-record-to-verify-your-domain-on-Mailgun-1024x276.png)**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](https://wpmailsmtp.com/a-beginners-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](https://wpmailsmtp.com/wp-content/uploads/2023/03/verify-dns-settings-smtp-1024x392.png)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](https://wpmailsmtp.com/wp-content/uploads/2022/10/Verify-domain-status-1024x562.png)[Fix Your WordPress Emails Now](https://wpmailsmtp.com/pricing/)

## 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](https://wpmailsmtp.com/wp-content/uploads/2023/08/select-api-security-option-1024x818.png)### 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](https://wpmailsmtp.com/wp-content/uploads/2023/08/create-api-key-button-1024x653.png)Add a description you’ll recognize later, then click **Create Key**.

![Adding a description to a new Mailgun API key](https://wpmailsmtp.com/wp-content/uploads/2023/08/add-description-and-click-create-key-1024x493.png)Copy the key with the copy icon and store it somewhere safe.

![Copying a new Mailgun API key](https://wpmailsmtp.com/wp-content/uploads/2023/08/click-to-copy-api-key-1024x681.png)**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](#aioseo-step-1-install-wp-mail-smtp-104)
- [Step 2: Launch the Setup Wizard](#aioseo-how-to-launch-the-setup-wizard)
- [Step 3: Select Mailgun as Your Mailer](#aioseo-how-to-select-mailgun-as-your-mailer)
- [How to Enter Your Mailgun Settings](#aioseo-how-to-enter-your-mailgun-settings)
- [Step 4: Enable Email Features](#aioseo-which-email-features-should-you-enable)
- [Step 5: How to Send a Test Email](#aioseo-how-to-send-a-test-email)

### Step 1: Install WP Mail SMTP

If you want to use Mailgun in WordPress, you need [WP Mail SMTP](https://wpmailsmtp.com/pricing/). 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](https://wpmailsmtp.com/wp-content/uploads/2026/09/search-plugin.png)Then click **Install Now** next to the WP Mail SMTP plugin.

![Install WP Mail SMTP plugin](https://wpmailsmtp.com/wp-content/uploads/2026/09/install-now.png)Once the installation completes, the button changes to “Activate”. Click on it to activate the plugin.

![Activate plugin](https://wpmailsmtp.com/wp-content/uploads/2026/09/activate-plugin.png)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](https://wpmailsmtp.com/wp-content/uploads/2022/12/launch-setup-wizard-1024x527.png)**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](https://wpmailsmtp.com/wp-content/uploads/2022/10/click-lets-get-started-button-1024x817.png)### 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](https://wpmailsmtp.com/wp-content/uploads/2026/09/select-mailgun-mailer.png "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 `support@example.com`. 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](https://wpmailsmtp.com/wp-content/uploads/2026/08/img_23_wizard-mailgun-settings.png "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](https://wpmailsmtp.com/wp-content/uploads/2023/08/select-email-features-1024x912.png)**Note:** Email logging needs a [paid WP Mail SMTP license](https://wpmailsmtp.com/pricing/ "Pricing").

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](https://wpmailsmtp.com/wp-content/uploads/2022/10/configure-email-logs-1-865x1024.png)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](https://wpmailsmtp.com/wp-content/uploads/2021/02/wp-mail-smtp-setup-wizard-license-key-1024x650.png)## 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](https://wpmailsmtp.com/wp-content/uploads/2021/02/finish-setup-1024x944.png)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](https://wpmailsmtp.com/wp-content/uploads/2021/02/wp-mail-smtp-setup-wizard-troubleshooting-1024x842.png)In my experience, 4 causes cover nearly every failure:

**What went wrong****How to fix it**DNS hasn’t propagatedWait up to 48 hours, then click **Verify DNS settings** in Mailgun againRegion mismatchMake the plugin’s Region match your Mailgun domain’s regionWrong API keyUse the Mailgun API key, not the Verification Public keyDomain mismatchThe plugin’s Domain Name must be the subdomain, not your root domainOlder 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](https://wpmailsmtp.com/how-to-fix-wp-mail-smtp-not-sending-test-email/) covers the less common errors.

**Pro Tip:** Add a [Backup Connection](https://wpmailsmtp.com/docs/configuring-backup-connection/ "Backup Connection") with a second mailer like [SendLayer](https://wpmailsmtp.com/docs/how-to-setup-the-sendlayer-mailer-using-quick-connect/ "How to Setup the SendLayer Mailer Using Quick Connect"). 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](https://wpmailsmtp.com/dmarc-spf-dkim/) 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](https://wpmailsmtp.com/pricing/)

Ready to fix your emails? [Get started today](https://wpmailsmtp.com/pricing) 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](https://facebook.com/wpmailsmtp) and [Twitter](https://twitter.com/wpmailsmtp) for more WordPress tips and tutorials.

**Categories:** WordPress Tutorials

---

