ramprasadm1986 / yii2-sendgrid
为Yii 2的Sendgrid邮件发送器
1.0.2
2020-10-23 07:34 UTC
Requires
- sendgrid/sendgrid: 2.2.1
This package is auto-updated.
Last update: 2024-09-23 16:00:38 UTC
README
Yii2 SendGrid
为Yii 2的Sendgrid邮件发送器
安装
安装此扩展的首选方式是通过 Composer。
你可以运行
php composer.phar require --prefer-dist ramprasadm1986/yii2-sendgrid "*"
或者在 composer.json
文件的 require 部分添加
"ramprasadm1986/yii2-sendgrid": "1.0.2"
来安装。
用法
安装扩展后,只需在代码中按照以下方式使用它
要使用邮件发送器,你应在应用配置中按照以下方式配置
'components' => [ ... 'sendGrid' => [ 'class' => 'ramprasadm1986\sendgrid\Mailer', 'username' => 'your_user_name', 'password' => 'your password here', //'viewPath' => '@app/views/mail', // your view path here ], ... ],
要发送邮件,你可以使用以下代码
$sendGrid = Yii::$app->sendGrid; $message = $sendGrid->compose('contact/html', ['contactForm' => $form]); $message->setFrom('from@domain.com') ->setTo($form->email) ->setSubject($form->subject) ->send($sendGrid);