craftcms / mailgun
Mailgun integration for Craft CMS
Package info
Type:craft-plugin
pkg:composer/craftcms/mailgun
Requires
- php: ^8.0.2
- craftcms/cms: ^4.0.0-alpha.1|^5.0.0-beta.1|^6.0.0-beta.1
- symfony/http-client: ^6.0.3|^7.0|^8.0
- symfony/mailgun-mailer: ^6.0.3|^7.0.4|^8.0
Requires (Dev)
- craftcms/ecs: dev-main
- craftcms/phpstan: dev-main
- craftcms/rector: dev-main
Suggests
- craftcms/yii2-adapter: Required to use Mailgun with Craft CMS 6.
Provides
None
Conflicts
None
Replaces
None
README
Mailgun for Craft CMS
This plugin provides a Mailgun integration for Craft CMS.
Requirements
This plugin requires Craft CMS 4.0.0+ or 5.0.0+, or 6.0.0-beta.1+ with the craftcms/yii2-adapter package.
You can install this plugin from the Plugin Store or with Composer.
From the Plugin Store
Go to the Plugin Store in your project’s Control Panel and search for “Mailgun”. Then click on the “Install” button in its modal window.
With Composer
Open your terminal and run the following commands:
# go to the project directory cd /path/to/my-project.test # tell Composer to load the plugin composer require craftcms/mailgun # tell Craft to install the plugin ./craft install/plugin mailgun
Setup
Once Mailgun is installed, go to Settings → Email, and change the “Transport Type” setting to “Mailgun”. Enter your domain name and Mailgun API Key (which you can get from your domain overview page) and click Save.
Tip: The Domain, API Key, and Endpoint settings can be set to environment variables. See Environmental Configuration in the Craft docs to learn more about that.
Craft 6
Craft 6 sends email through Laravel mailers. Laravel has its own Mailgun driver, so you don’t need this plugin once you’ve configured it.
With the craftcms/yii2-adapter package installed, Craft can keep sending email through the Mailgun settings in your project config, as the craft-transport mailer. To use it, set MAIL_MAILER=craft-transport in your environment, or choose craft-transport as the mailer in Settings → Email. (Craft only falls back to it on its own when neither is set and the default mailer in config/mail.php is still log.) The Yii2 Loose Ends utility lists the Mailgun settings until you configure a Laravel mailer.
To configure Laravel’s Mailgun driver:
-
Require Symfony’s Mailgun transport and HTTP client. Removing this plugin removes them too, otherwise.
composer require symfony/mailgun-mailer symfony/http-client
-
Add a
mailgunmailer to themailersarray inconfig/mail.php:'mailgun' => [ 'transport' => 'mailgun', ],
-
Add your Mailgun credentials to
config/services.php:'mailgun' => [ 'domain' => env('MAILGUN_DOMAIN'), 'secret' => env('MAILGUN_SECRET'), 'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'), 'scheme' => 'https', ],
-
Set the environment variables in
.env.MAILGUN_SECRETis the API key.MAILGUN_ENDPOINTis a hostname withouthttps://, such asapi.eu.mailgun.netfor Mailgun’s EU region.MAIL_MAILER=mailgun MAILGUN_DOMAIN=mg.example.com MAILGUN_SECRET=your-api-key MAILGUN_ENDPOINT=api.mailgun.net
-
Send a test email from Settings → Email, or with
php artisan craft:mailer:test.
Then uninstall the plugin and remove it from your project:
php artisan craft:plugin:uninstall mailgun composer remove craftcms/mailgun