wowmaking/yii2-mailgun
Composer 安装命令:
composer require wowmaking/yii2-mailgun
包简介
Mailgun integration for the Yii framework
README 文档
README
This extension provides a Mailgun mail solution for Yii framework 2.0.
Installation
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
Usage
To use this extension, simply add the following code in your application configuration:
return [ //.... 'components' => [ 'mailer' => [ 'class' => 'boundstate\mailgun\Mailer', 'key' => 'key-example', 'domain' => 'mg.example.com', ], ], ];
You can then send an email as follows:
Yii::$app->mailer->compose('contact/html', ['contactForm' => $form]) ->setFrom('from@domain.com') ->setTo($form->email) ->setSubject($form->subject) ->send();
You can also specify an array of addresses and/or speicfy names:
$message->setTo(['bob@example.com' => 'Bob']);
Warning: By default all recipients' email address will show up in the
tofield 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:
Yii::$app->mailer->compose('hello') ->setTo([ 'bob@example.com' => [ 'id': 3, 'full_name' => 'Bob' ], 'jane@example.com' => [ 'id': 4, 'full_name' => 'Jane' ], ]) ->setSubject('Hi %recipient.full_name%') ->send();
For further instructions refer to the Mailgun docs and the related section in the Yii Definitive Guide.
统计信息
- 总下载量: 321
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2025-09-08