Skip to content
Mon-Fri: 9:00 - 18:00 Engineering Intelligent CRM, SaaS & Scalable AI Infrastructure

How to Connect Mailgun to WordPress (Step-by-Step Guide)

This guide explains how to properly connect Mailgun to a WordPress website to ensure reliable email delivery for forms, notifications, and system emails.


Why Use Mailgun?

WordPress sends emails using the server’s default mail function, which is often unreliable. Emails may:

  • Go to spam
  • Not be delivered at all
  • Fail silently

Mailgun is a professional email delivery service that solves these issues by providing:

  • High deliverability
  • Authentication (SPF, DKIM)
  • Email logs and tracking

Overview of the Setup

To connect Mailgun to WordPress, you will:

  1. Create a Mailgun account
  2. Add a sending domain (subdomain)
  3. Configure DNS records
  4. Connect Mailgun to WordPress via SMTP plugin
  5. Configure form emails (e.g., Gravity Forms)
  6. Test email delivery

Step 1 — Create a Mailgun Account

Go to:
https://www.mailgun.com

Sign up or log in to your account.


Step 2 — Add a Sending Domain

Inside Mailgun:

  • Navigate to Sending → Domains
  • Click Add New Domain

Use a subdomain (recommended):

Example:

mg.yourdomain.com

Select region (US or EU), then click Add Domain.


Step 3 — Configure DNS Records

Mailgun will provide DNS records you must add to your domain.

These typically include:

1. SPF (TXT)

Host: mg

Value: v=spf1 include:mailgun.org ~all

2. DKIM (TXT)

Host: k1._domainkey.mg

Value: (long key provided by Mailgun)

3. MX Records

Host: mg

Value: mxa.mailgun.org (Priority 10)

Host: mg

Value: mxb.mailgun.org (Priority 10)

4. Tracking (CNAME)

Host: email.mg

Value: mailgun.org

⚠️ Important:

  • Enter only the host name (e.g., mg), not the full domain
  • DNS changes may take 5–60 minutes to propagate

After adding records, return to Mailgun and click Verify DNS.


Step 4 — Install SMTP Plugin in WordPress

Install the plugin:

  • WP Mail SMTP

In WordPress:

  • Go to Plugins → Add New
  • Search for “WP Mail SMTP”
  • Install and activate

Step 5 — Configure Mailgun in WordPress

Go to:
WP Mail SMTP → Settings

Set:

Mailer: Mailgun

API Key: your Mailgun API key

Domain: mg.yourdomain.com

Region: US or EU

Save settings.


Step 6 — Send Test Email

Go to:
WP Mail SMTP → Tools → Email Test

Send a test email to verify configuration.

If successful, Mailgun is correctly connected.


Step 7 — Configure Gravity Forms (or other forms)

If using Gravity Forms:

Go to:
Forms → Your Form → Settings → Notifications

Set:

From Email: noreply@yourdomain.com

Reply-To: {Email:1} (user email field)

⚠️ Important:

  • The “From Email” must match your domain
  • Do NOT use Gmail or unrelated domains

Step 8 — Test Form Submission

Submit the form and verify:

  • Email is received
  • Email is not in spam
  • Mailgun logs show successful delivery

Common Issues

Emails not sending

  • Check API key and domain
  • Verify DNS records in Mailgun

Emails going to spam

  • Ensure SPF and DKIM are verified
  • Use domain-based email (not Gmail)

DNS not verifying

  • Wait for propagation
  • Check for typos in host names

Best Practices

  • Use a subdomain like mg.yourdomain.com
  • Keep one Mailgun account for multiple sites
  • Use domain-based “From Email”
  • Monitor logs in Mailgun dashboard

Conclusion

Connecting Mailgun to WordPress ensures reliable email delivery for forms and notifications. Once configured, it significantly improves email success rate and reduces spam issues.

This setup is especially important for business websites where missing form submissions can lead to lost leads.

Other blogs
Payment Integration — Part 2: Recurring Payments, Webhooks & Flexible Discounts (Stripe Edition)

Hey everyone! In the first part we agreed: redirects are evil, business logic stays on…

3 Mistakes I Made Automating Workflows with AI, and What They Taught Me

AI has made automation more accessible than ever. Tasks that previously required hours of manual…

Payment Integration

Hey everyone! I’m starting a series of articles on integrating payments into a website. If…