How to Use Mailgun with WordPress Multisite – HTTP API or SMTP

Mailgun is my goto for transactional email with WordPress and WooCommerce. You get up to 10k free emails per month with them and each additional email costs a fraction of a penny! Mailgun does work well with WordPress multisite with a few extra steps of configuration compared to a more standard vanilla WordPress single site setup. This tutorial will show you how to get all of these settings in place so Mailgun will work with your multisite.

How to Use Mailgun with WordPress Multisite

We are going to split this up into the Mailgun settings and the WordPress Mailgun Plugin settings

Mailgun settings

If you are using WordPress mulsitie with subdomains, you will want to enable the wildcard domain option in Mailgun’s panel.

You can navigate to the Mailgun settings by going to this URL, change to your Mailgun domain

Scroll down to Domain Settings,  next to Wildcard Domain click the pencil, choose Wildcard domain and click Save Wildcard Settings.

We also need the Mailgun credential information, for using the HTTP API you will need the API key.

For SMTP you will need the default user postmaster (Default SMTP Login) and the SMTP password (Default Password).

Mailgun Multisite Plugin Settings

You need to install Mailgun WordPress plugin and Network Activate the plugin.

The Mailgun settings we need to add go in your wp-config.php which you can edit with a plugin like WP File Manager or using FTP.

I put them after these settings

 * WordPress Database Table prefix.
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
$table_prefix = 'wp_';

/** Enable or disable Worpress Multi-site features **/
define('WP_ALLOW_MULTISITE', true);

define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', '');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

and before these lines

/* That's all, stop editing! Happy blogging. */

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) )
        define( 'ABSPATH', dirname( __FILE__ ) . '/' );

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';

Here are the various settings for using Mailgun with WordPress multisite using either the HTTP API or SMTP.

WordPress Multisite Mailgun HTTP API Settings

Add the lines below to use the Mailgun HTTP API for your multisite.

Make sure to change key-YourAPIKeyHere to your Mailgun API Key.

Also change the to your Mailgun domain.

//Mailgun HTTP API Multisite
define('MAILGUN_USEAPI', true);
define('MAILGUN_APIKEY', 'key-YourAPIKeyHere');
define('MAILGUN_DOMAIN', '' );
define('MAILGUN_SECURE', true);

That should take care of the HTTP API settings for Mailgun with Multisite!

WordPress Multisite Mailgun SMTP Settings

For using Mailgun SMTP with WordPress Multisite, use these settings.

Remember to adjust to your Mailgun domain.

Change the password to your postmaster’s Default SMTP Password.

//Mailgun SMTP Multisite
define('MAILGUN_USEAPI', false);
define('MAILGUN_DOMAIN', '' );
define('MAILGUN_USERNAME', 'postmaster');
define('MAILGUN_PASSWORD', 'YourMailgunSMTPPassword');
define('MAILGUN_SECURE', true);

This should get the Mailgun SMTP working with WordPress multisite!

WordPress Multisite Mailgun All Settings

If you want all of the options so you can easily change them by commenting lines out with // as necessary, use this snippet

//Mailgun multisite stuff
define('MAILGUN_USEAPI', true);
define('MAILGUN_APIKEY', 'key-YourAPIKeyHere');
define('MAILGUN_DOMAIN', '' );
//Required for SMTP if USEAPI is false
//define('MAILGUN_USERNAME', 'postmaster');
//define('MAILGUN_PASSWORD', 'YourMailgunSMTPPassword');
define('MAILGUN_SECURE', true);
// Set the from name and from address
define('MAILGUN_FROM_NAME', 'WP Bullet');

That should do it!

A quick and easy test to see if Mailgun is working with multisite is to change your password within WordPress which should send you a Notice of Password change email.


How to use Mailgun with Multisite
Mailgun WordPress Plugin – Multi-site Define Settings