Mailgun integration for the Yii framework

Installs: 27 022

Dependents: 0

Suggesters: 0

Security: 0

Stars: 24

Watchers: 7

Forks: 31

Open Issues: 0


v1.3.0 2020-10-28 19:12 UTC

This package is auto-updated.

Last update: 2020-11-28 19:34:01 UTC


This extension provides a Mailgun mail solution for Yii framework 2.0.

Latest Stable Version Total Downloads Build Status


The preferred way to install this extension is through composer.

composer require boundstate/yii2-mailgun

The Mailgun API Client is not hard coupled to Guzzle, Buzz or any other library that sends HTTP messages. You must also install the PSR-7 implementation and HTTP client you want to use.

If you just want to get started quickly you should install Buzz and nyholm/psr7:

composer require kriswallsmith/buzz nyholm/psr7


To use this extension, simply add the following code in your application configuration:

return [
    'components' => [
        'mailer' => [
            'class' => 'boundstate\mailgun\Mailer',
            'key' => 'key-example',
            'domain' => '',

You can then send an email as follows:

Yii::$app->mailer->compose('contact/html', ['contactForm' => $form])

You can also specify an array of addresses and/or speicfy names:

$message->setTo(['' => 'Bob']);

Warning: By default all recipients' email address will show up in the to field for each recipient. Enable batch sending to avoid this.

Batch Sending

When batch sending is enabled, Mailgun sends each recipient an individual email with only their email in the to field.

To use batch sending, set the messageClass to boundstate\mailgun\BatchMessage in your application configuration:

'mailer' => [
    'class' => 'boundstate\mailgun\Mailer',
    'messageClass' => 'boundstate\mailgun\BatchMessage',
    // ...

Composing a batch email is similar to regular emails, except you may define and use recipient variables:

      '' => [
        'id': 3,
        'full_name' => 'Bob'
      '' => [
        'id': 4,
        'full_name' => 'Jane'
    ->setSubject('Hi %recipient.full_name%')

For further instructions refer to the Mailgun docs and the related section in the Yii Definitive Guide.