thiagotalma/yii2-sendgrid

Sendgrid Mailer for Yii2

Installs: 5 102

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 3

Forks: 0

Type:yii2-extension

v0.1 2016-08-29 15:43 UTC

This package is not auto-updated.

Last update: 2024-12-21 20:30:44 UTC


README

Sendgrid Mailer for Yii2

based on shershennm/yii2-sendgrid

Latest Stable Version Total Downloads

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',
	]);