我试图在Yii 2中使用sendgrid来获取邮件,但它似乎没有用。可以告诉我yii2中的sendgrid步骤。
答案 0 :(得分:2)
您可以使用https://github.com/bryglen/yii2-sendgrid#yii-2-bryglen-sendgrid
安装:
composer require --prefer-dist bryglen/yii2-sendgrid "*"
公共/配置/ main.php
'components' => [
...
'sendGrid' => [
'class' => 'bryglen\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);