jafarili / yii2-mailjet
Mailjet 客户端
v0.3.0
2021-01-26 19:04 UTC
Requires
- mailjet/mailjet-apiv3-php: ^1.1.5
This package is auto-updated.
Last update: 2024-09-27 03:17:03 UTC
README
创建 Mailjet 账户
安装
composer require jafarili/yii2-mailjet
或将其添加到 composer.json 文件的 require 部分
"jafarili/yii2-mailjet": "*",
配置
在 config 文件 components 键下添加/替换以下内容。
'components' => [
'mailer' => [
'class' => 'Jafarili\mailjet\Mailer',
'apikey' => 'yourApiKey',
'secret' => 'yourSecret',
],
],
或者设置一个 MailJet 客户端
'components' => [
'mailer' => [
'class' => 'Jafarili\mailjet\Mailer',
'mailjet' => new \Mailjet\Client('yourApiKey', 'yourSecret'),
],
],
示例
Yii::$app->mailer->compose('signup', ['user' => $user])
->setTo($user->email)
->setFrom([Yii::$app->params['noReplyMailAddress'] => Yii::$app->name])
->setSubject('Signup success')
->send();
附件示例
// Mail with attachment from string via Message::attachContent()
Yii::$app->mailer->compose('view-name')
->setSubject('Mail with attachment from content')
->attachContent("This is the attachment content", ['fileName' => 'attachment.txt', 'contentType' => 'text/plain'])
->setTo('info@example.com')
->send();
// Mail with attachment from file via Message::attach()
$filePath = ... // a file path here;
Yii::$app->mailer->compose('view-name')
->setSubject('Mail with attachment from content')
->attach($filePath)
->setTo('info@example.com')
->send();
设置事件跟踪
将跟踪项写入邮件发送配置。
'components' => [
'mailer' => [
'class' => 'Jafarili\mailjet\Mailer',
'apikey' => 'yourApiKey',
'secret' => 'yourSecret',
'tracking' => [
'bounce' => 'http://yoururl.com/tracking?event=bounce',
],
],
],
要激活此 URL,必须一次性运行此命令。
Yii::$app->mailer->activateTracking();