Send mail using YiiMail extension

Introduction ΒΆ

Let me show a simpe example to send mail using YiiMail extension in 5 steps. It also includes any template view if required along with the content.

Step1: Download the extension from path '' .

Step 2: Place the extracted folder inside the extensions folder.

Step 3: Modify the config file main.php like below,

'mail' => array(
				'class' => 'ext.yii-mail.YiiMail',
				'viewPath' => 'application.views.mail',				

Hint: The view path points to '/protected/views/mail'.

Step 4: Import the extension in the main.php file .


Step 5: Controller function to send the mail.

public function SendMail()
		$message            = new YiiMailMessage;
           //this points to the file test.php inside the view path
		$message->view = "test";
		$sid                 = 1;
		$criteria            = new CDbCriteria();
		$criteria->condition = "studentID=".$sid."";			
		$studModel1 	     = Student::model()->findByPk($sid);		
		$params              = array('myMail'=>$studModel1);
		$message->subject    = 'My TestSubject';
		$message->setBody($params, 'text/html');				
		$message->from = 'admin@domain .com';	

 test.php file
			Dear <?php 
			 echo $myMail->studentName;
 				<br>This is a test mail.

That's it. Run the code and mail is sent.

5 0
Viewed: 79 279 times
Version: 1.1
Category: Tutorials
Tags: YiiMail
Written by: RKA
Last updated by: RKA
Created on: Mar 19, 2013
Last updated: 5 years ago
Update Article


View all history