rahulk-k / yii2-sendgrid
使用Sendgrid发送电子邮件
1.0.0
2019-10-20 13:23 UTC
Requires
- sendgrid/sendgrid: ^7.3
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-09-13 16:11:19 UTC
README
Yii 2的Sendgrid邮件发送器
安装
安装此扩展的首选方式是通过 composer。
您可以选择运行
php composer.phar require --prefer-dist rahulk-k/yii2-sendgrid "*"
或向您的 composer.json
文件的 require 部分添加
"rahulk-k/yii2-sendgrid": "~1.0"
。
使用方法
一旦安装了扩展,只需在代码中通过以下方式使用它
要使用邮件发送器,您应该在应用程序配置中配置它,如下所示
'components' => [ ... 'sendgrid' => [ 'class' => 'rahul\sendgrid\Mailer', 'username' => 'your_user_name', 'password' => 'your password here', 'token' => 'your token', //'viewPath' => '@app/views/mail', // your view path here ], ... ],
要发送电子邮件,您可以使用以下代码
Yii::$app->sendgrid->compose('contact/html', ['contactForm' => $form]) ->setFrom(['from@domain.com'=>'John Due']) ->setTo($form->email) ->setSubject($form->subject) ->send();