ramprasadm1986/yii2-sendgrid

为Yii 2的Sendgrid邮件发送器

安装: 54

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:yii2-extension

1.0.2 2020-10-23 07:34 UTC

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