thiagotalma / yii2-sendgrid
Sendgrid Mailer for Yii2
Installs: 5 097
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Type:yii2-extension
Requires
- sendgrid/sendgrid: ~4.0
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2024-10-26 19:38:00 UTC
README
Sendgrid Mailer for Yii2
based on shershennm/yii2-sendgrid
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist thiagotalma/yii2-sendgrid "*"
or add
"thiagotalma/yii2-sendgrid": "*"
to the require section of your composer.json
file.
Usage
To use Mailer, you should configure it in the application configuration like the following:
Usign API Key:
'components' => [ ... 'mailer' => [ 'class' => 'thiagotalma\sendgrid\Mailer', 'key' => 'your api key', //'viewPath' => '@app/views/mail', // your view path here ], ... ],
Usign username and password:
'components' => [ ... 'mailer' => [ 'class' => 'thiagotalma\sendgrid\Mailer', 'username' => 'your username', 'password' => 'your password here', //'viewPath' => '@app/views/mail', // your view path here ], ... ],
To send an email, you may use the following code:
$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', ]);