rahulk-k/yii2-sendgrid

使用Sendgrid发送电子邮件

安装: 6

依赖: 0

建议者: 0

安全: 0

星级: 1

关注者: 2

分支: 0

开放性问题: 0

类型:yii2-extension

1.0.0 2019-10-20 13:23 UTC

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();