A
A
Alexander Ampleev2018-04-18 15:04:32
Yii
Alexander Ampleev, 2018-04-18 15:04:32

How to set up sending mail via sendgrid in yii2?

I use this package https://github.com/bryglen/yii2-sendgrid
I want mail to be sent via sendgrid.
in composer

"sendgrid/sendgrid": "2.2.1",
        "bryglen/yii2-sendgrid": "1.1.3"

in config
'sendGrid' => [
            'class' => 'bryglen\sendgrid\Mailer',
            'username' => 'username',
            'password' => 'password',
            //'viewPath' => '@app/views/mail', // your view path here
        ],

in SiteController.php
public function actionTest()
    {
        $sendGrid = Yii::$app->sendGrid;
        $message = $sendGrid->compose('contact/html', ['contactForm' => $form]);

        $message->setFrom('[email protected]')
            ->setTo('[email protected]')
            ->setSubject('test')
            ->send($sendGrid);

    }

as a result, the error "Undefined variable: form"
- and what should be in this variable is not clear ..

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Ampleev, 2018-04-18
@Ampleev

in general, I scored on this package and did everything through it according to the instructions https://packagist.org/packages/sendgrid/sendgrid

M
Maxim Fedorov, 2018-04-18
@qonand

and what should be in this variable is not clear ..

Well, judging by the line 'contactForm' => $form, it should contain some data that you want to send in a letter. What kind of data is known only to God and you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question