Difference between #2 and #1 of Send mail using YiiMail extension

changed
Title
SendingSend mail using YiiMail extension
unchanged
Category
Tutorials
unchanged
Tags
YiiMail
changed
Content
**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
'[http://code.google.com/p/yii-mail/downloads/list](http://code.google.com/p/yii-mail/downloads/list
"YiiMailExtension")' .

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

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


~~~
[php]
'mail' => array(
				'class' => 'ext.yii-mail.YiiMail',
				'transportType'=>'smtp',
				'transportOptions'=>array(
						'host'=>'<hostanme>',
						'username'=>'<username>',
						'password'=>'<password>',
						'port'=>'25',						
				),
				'viewPath' => 'application.views.mail',				
		),
~~~


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

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

~~~
[php]
  'ext.yii-mail.YiiMailMessage',
~~~


**Step 5:** Controller function to send the mail.
  
       

~~~
[php]
   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->addTo('yourmail@domain.com');
		$message->from = 'admin@domain .com';	
		Yii::app()->mail->send($message);		
	}

~~~


     test.php file
      

~~~
[php]
    <html>
		<head>
		</head>
		<body>
			Dear <?php 
			 echo $myMail->studentName;
			 ?>
 				<br>This is a test mail.
		</body>
	   </html>

~~~


 That's it. Run the code and mail is sent.
Write new article
  • Written by: RKA
  • Category: Tutorials
  • Yii Version: 1.1
  • Votes: +8
  • Viewed: 37,037 times
  • Created on: Mar 19, 2013
  • Last updated: Mar 19, 2013
  • Tags: YiiMail