shershennm / yii2-sendgrid
为 Yii 2 的 Sendgrid 邮件发送器
3.1.1
2019-05-27 13:55 UTC
Requires
- sendgrid/sendgrid: ^7.0
- yiisoft/yii2: ^2.0.4
Requires (Dev)
- codeception/codeception: ^2.4
README
为 Yii 2 的 Sendgrid 邮件发送器
forked from bryglen/yii2-sendgrid
3.1.0 更新
之前返回 \SendGrid\Mail\EmailAddress
或此类型数组的函数,现在返回普通电子邮件字符串或 ['email' => 'name']
数组或包含此值的数组。
安装
安装此扩展的首选方式是通过 composer。
运行以下命令:
php composer.phar require --prefer-dist shershennm/yii2-sendgrid "^3.1"
或者
"shershennm/yii2-sendgrid": "^3.1"
将以下内容添加到你的 composer.json
文件的 require 部分中。
使用方法
扩展安装后,只需在你的代码中使用即可
要使用 Mailer,应在应用配置中按以下方式配置:
'components' => [ ... 'sendGrid' => [ 'class' => 'shershennm\sendgrid\Mailer', 'apiKey' => 'your api key', ] ... ],
发送电子邮件,可以使用以下代码
$sendGrid = Yii::$app->sendGrid; $message = $sendGrid->compose('contact/html', ['contactForm' => $form]) $message->setFrom('from@domain.com') ->setTo($form->email) ->setSubject($form->subject) ->send($sendGrid); //also you can use sendgrid substitutions ->setSendGridSubstitution('template id', [ ':var1' => 'var1value', ':var2' => 'var2value', ]);