thiagotalma / yii2-sendgrid
Yii2的Sendgrid邮件发送器
v0.1
2016-08-29 15:43 UTC
Requires
- sendgrid/sendgrid: ~4.0
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2024-09-14 19:14:50 UTC
README
Yii2的Sendgrid邮件发送器
安装
安装此扩展的最佳方式是通过composer。
运行以下命令之一
php composer.phar require --prefer-dist thiagotalma/yii2-sendgrid "*"
或者
"thiagotalma/yii2-sendgrid": "*"
将以下内容添加到您的composer.json
文件的require部分。
使用方法
要使用Mailer,您应该在应用程序配置中对其进行配置,如下所示
使用API密钥
'components' => [ ... 'mailer' => [ 'class' => 'thiagotalma\sendgrid\Mailer', 'key' => 'your api key', //'viewPath' => '@app/views/mail', // your view path here ], ... ],
使用用户名和密码
'components' => [ ... 'mailer' => [ 'class' => 'thiagotalma\sendgrid\Mailer', 'username' => 'your username', 'password' => 'your password here', //'viewPath' => '@app/views/mail', // your view path here ], ... ],
要发送电子邮件,您可以使用以下代码
$sendGrid = Yii::$app->mailer; $message = $sendGrid->compose('contact/html', ['contactForm' => $form]) $message->setFrom('from@domain.com') ->setTo($form->email) ->setSubject($form->subject) ->send(); //also you can use sendgrid substitutions ->setSendGridSubstitution('template id', [ ':var1' => 'var1value', ':var2' => 'var2value', ]);