i want to send automatic mail to users, containing user password. i’ve been instructed to use sendgrid for this purpose. i wanna know in detail how to integrate sengrid in yii2.
regards,
Ajith
i want to send automatic mail to users, containing user password. i’ve been instructed to use sendgrid for this purpose. i wanna know in detail how to integrate sengrid in yii2.
regards,
Ajith
my configuration is as follows:
‘components’ => [
...
'sendGrid' => [
'class' => 'bryglen\sendgrid\Mailer',
'username' => 'your_user_name',
'password' => 'your password here',
//'viewPath' => '@app/views/mail', // your view path here
],
...
],
To send an email, i have used the following code:
$sendGrid = Yii::$app->sendGrid;
$message = $sendGrid->compose(‘contact/html’, [‘contactForm’ => $form])
$message->setFrom(‘from@domain.com’)
->setTo($form->email)
->setSubject($form->subject)
->send($sendGrid);
and i get an error like this
Error
PHP Parse Error – yii\base\ErrorException
syntax error, unexpected ‘$message’ (T_VARIABLE)
1. in /home/user/public_html/ims/controllers/CustomersController.php at line 96
87888990919293949596979899100101102103104105
$model1->password=$a;
$model1->customer_id=$model->id;
$model1->email=$model->customer_email;
$model1->type="user";
$model1->user_status="0";
$model1->save();
$sendGrid = Yii::$app->sendGrid;
$message = $sendGrid->compose('contact/html', ['contactForm' => $form])
$message->setFrom('from@domain.com')
->setTo($form->email)
->setSubject($form->subject)
->send($sendGrid);
//~ $message = Yii::$app()->sendgrid->createEmail();
//~ //shortcut to $message=new YiiSendGridMail($viewsPath);
//~ $message->setHtml('<p>Message content here with HTML</p>')
//~ ->setSubject('My Subject')
//~ ->addTo('paulpelias@gmail.com')
//~ ->setFrom('nivya@drishyatech.com');
2. yii\base\ErrorHandler::handleFatalError()
$_GET = [
'r' => 'customers/create',
];
$_POST = [
'_csrf' => 'Y3JxYUlfRUcmJzg7BBELCAwTGiMjBnE1KAESNxs.MC9aMxYAPg8Odg==',
'Customers' => [
'customer_name' => 'Rafel Nadal',
'customer_address' => 'rafa villa mallorca',
'customer_email' => 'leejose4u@gmail.com',
],
];
$_SERVER = [
'HTTP_HOST' => 'localhost',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0',
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.5',
'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
'HTTP_REFERER' => 'http://localhost/~user/ims/web/index.php?r=customers/create',
'HTTP_COOKIE' => '_csrf=c1c2de5c688675cf2ac71f86d3c380adba377e82b6a168f4928aa2fd82a36a6ea%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22_csrf%22%3Bi%3A1%3Bs%3A32%3A%22EUIZMNNOoakBjY4rKscVRauh9AgawPK1%22%3B%7D; PHPSESSID=9m0jvd61at2cn8hflm7hk0sd35',
'HTTP_CONNECTION' => 'keep-alive',
'HTTP_CACHE_CONTROL' => 'max-age=0',
'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
'CONTENT_LENGTH' => '211',
'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
'SERVER_SIGNATURE' => '',
'SERVER_SOFTWARE' => 'Apache/2.4.7',
'SERVER_NAME' => 'localhost',
'SERVER_ADDR' => '127.0.0.1',
'SERVER_PORT' => '80',
'REMOTE_ADDR' => '127.0.0.1',
'DOCUMENT_ROOT' => '/var/www/html',
'REQUEST_SCHEME' => 'http',
'CONTEXT_PREFIX' => '/~user',
'CONTEXT_DOCUMENT_ROOT' => '/home/user/public_html',
'SERVER_ADMIN' => 'webmaster@localhost',
'SCRIPT_FILENAME' => '/home/user/public_html/ims/web/index.php',
'REMOTE_PORT' => '42140',
'GATEWAY_INTERFACE' => 'CGI/1.1',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'REQUEST_METHOD' => 'POST',
'QUERY_STRING' => 'r=customers/create',
'REQUEST_URI' => '/~user/ims/web/index.php?r=customers/create',
'SCRIPT_NAME' => '/~user/ims/web/index.php',
'PHP_SELF' => '/~user/ims/web/index.php',
'REQUEST_TIME_FLOAT' => 1427088907.1329999,
'REQUEST_TIME' => 1427088907,
];
$_COOKIE = [
'_csrf' => 'c1c2de5c688675cf2ac71f86d3c380adba377e82b6a168f4928aa2fd82a36a6ea:2:{i:0;s:5:"_csrf";i:1;s:32:"EUIZMNNOoakBjY4rKscVRauh9AgawPK1";}',
'PHPSESSID' => '9m0jvd61at2cn8hflm7hk0sd35',
];
Yii Framework
2015-03-23, 05:35:07
Apache/2.4.7
Yii Framework/2.0.3
$sendGrid = Yii::$app->sendGrid;
$message = $sendGrid->compose(‘contact/html’, [‘contactForm’ => $form])[color="#FF0000"];[/color]
$message->setFrom(‘from@domain.com’)
->setTo($form->email)
->setSubject($form->subject)
->send($sendGrid);
You’re missing a semicolon on the second line at the end. I colored it red above.