sendgrid Sendgrid email component

yii-sendgrid extension

  1. Requirements
  2. Instalattion
  3. How to use
  4. Resources
View on GitHub
Download now

YiiSendGrid is an application component used for sending email through sendgrid.
It's a wrapper for SendGrid php library

You may configure it as below. Check the attributes of YiiSendGrid class and YiiSendGridMail class for more options.


  • PHP 5.3+


Download the file and extract to protected/extensions (or anywhere you like, but then adjust the example accordingly)

Add the component to your configuration file (usually protected/configs/main.php) as below:

return array(  
	'components' => array(  
 		'sendgrid' => array(  
 			'class' => 'ext.yii-sendgrid.YiiSendGrid', //path to YiiSendGrid class  
 			'username'=>'myUsername', //replace with your actual username  
 			'password'=>'myP4s$w0rd', //replace with your actual password  
 			//alias to the layouts path. Optional  
 			//'viewPath' => 'application.views.mail',  
 			//wheter to log the emails sent. Optional  
 			//'enableLog' => YII_DEBUG, 
 			//if enabled, it won't actually send the emails, only log. Optional  
 			//'dryRun' => false, 
 			//ignore verification of SSL certificate  

How to use

Examples of use

$message = Yii::app()->sendgrid->createEmail();  
//shortcut to $message=new YiiSendGridMail($viewsPath);  
$message->setHtml('<p>Message content here with HTML</p>')  
	->setSubject('My Subject')   

or just

$message = Yii::app()->sendgrid->createEmail($htmlBody,$subject,$to,$from);  

A more real life and complete example using a view and optionally a layout

/* @var $sg YiiSendGrid */
$message = $sg->createEmail();  
//set view variable $user  
	->setView('signup') //view located in YiiSendGrid::$viewPath. Defaults to protected/views/mail  
		'user'=>$user//my User model. Pass it to the view as $user, same way controller does  
// optionally you can use a layout  
$message->setSubject('Welcome to '.Yii::app()->name.'!')  
//handle errors
	Yii::log("Failed to send email:\n".print_r($sg->lastErrors,true) ,CLogger::LEVEL_ERROR);


1 0
Yii Version: Unknown
License: MIT
Category: Mail
Developed by: Gustavo
Created on: Mar 9, 2014
Last updated: 8 years ago


show all

Related Extensions