Sendgrid Yii2 integration
This extension allow the developper to use Sendgrid as an email transport., (*1)
, (*2)
, (*3)
Installation
If you use Packagist for installing packages, then you can update your composer.json like this :, (*4)
``` json
{
"require": {
"dutchakdev/yii2-sendgrid": "*"
}
}, (*5)
Howto use it
------------
Add extension to your configuration
``` php
return [
//....
'components' => [
'mailer' => [
'class' => 'dutchakdev\sendgrid\Mailer',
'token' => '<your sendgrid token>',
],
],
];
You can send email as follow (using postmark templates), (*6)
``` php
Yii::$app->mailer->compose('contact/html')
->setFrom('from@domain.com')
->setTo($form->email)
->setSubject($form->subject)
->setTemplateId(12345)
->setTemplateModel([
'firstname' => $form->firstname,
'lastname' => $form->lastname,
->send();, (*7)
For further instructions refer to the [related section in the Yii Definitive Guide](http://www.yiiframework.com/doc-2.0/guide-tutorial-mailing.html)
Running the tests
-----------------
Before running the tests, you should edit the file tests/_bootstrap.php and change the defines :
``` php
// ...
define('SENDGRID_FROM', '<sender>');
define('SENDGRID_TOKEN', '<token>');
define('SENDGRID_TO', '<target>');
define('SENDGRID_TEMPLATE', 575741);
define('SENDGRID_TEST_SEND', false);
// ...
to match your Sendgrid configuration., (*8)
Contributing
All code contributions - including those of people having commit access -
must go through a pull request and approved by a core developer before being
merged. This is to ensure proper review of all the code., (*9)
Fork the project, create a feature branch , and send us a pull request., (*10)