Troubleshooting Mailgun integration with Statamic V3

T

On my live Statamic production site, I was having trouble making MailGun work for sending emails.

Perhaps the extra steps I followed will help someone else who gets stuck, too.

My Statamic V3 set-up is as follows:

  • PEAK (Statamic starter kit)
  • MailGun
  • Digital Ocean Droplet
  • Laravel Forge
  • Git Hub repository

Mail settings are configured in Environment Files

In my case, the production site’s environment file (or .env file) is edited and accessed from logging into your account on https://forge.laravel.com. Select your site from the Sites drop-down and choose Environment.

I had the first 8 lines filled out properly for MailGun, but I did not have the last two lines shown above included. After I added those two lines (Saved and Redeployed in Forge), my emails started working as expected.

  • MAILGUN_DOMAIN=
  • MAILGUN_SECRET=

The MAILGUN_SECRET is the Mailgun secret key and can be found by logging into MailGun and going to Settings -> API Keys -> API Security > Private API key (it is a long key, use the eye icon to make it visible).

For Newbies: If you’re still new to .env files, one other thing to point out is that spaces can not be included in values. If you’re using a space, make sure to include quotes. For instance, in the MAIL_FROM_NAME, I made it:

MAIL_FROM_NAME='First Last'

Other TroubleShooting

  • You may want to check that you do not have your mail settings accidentally defined in duplicate.
  • Double-check that Guzzler is added properly as a dependency via composer. Use the terminal command
composer require guzzlehttp/guzzle

If any of these three items are wrong, you may receive a 401 unauthorized error. You can read more about troubleshooting for this 401 error on this Laracasts forum post.

Additional Useful Docs for Configuring Mailgun in Statamic

Laravel.com’s Mail Driver PreRequisite Docs

Statamic Docs for Sending Mail

Don’t forget, Statamic has a great test feature for emails.

Within your Statamic Site’s Contol Panel, Go to Utilities -> Email and simply add your email address and click Send Test Email (blue button). Within seconds, you’ll receive an email from a properly configured Mailgun/Statamic setup.

Easy way to send test email in Statamic Control Panel

If you have additional insights or experiences with Mailgun and Statamic, please share in the comments below.

About the author

Kelly Barkhurst

Designer to Fullstack is my place to geek out and to share tech solutions from my day-to-day as a designer, programmer, and business owner (portfolio). I also write on Arts and Bricks, a parenting blog and decal shop that embraces my family’s love of Art and LEGO bricks!

Add comment

By Kelly Barkhurst

Recent Posts

Archives

Categories