The Email template Path of Yii-Email extensions

Usually, when we use the yii-mail.  If we use our own themes.  The email template seems store at

 <webroot>\protected\views\mail\xxx.php, It's not good for us to maintain the email template.

 Suppose  our themes name is  “Patrick”,  When send the email, the email content should be found at <webroot>\patrick\views\mail\xxx.php

 

And we need to change the  file  of  YiiMailMessage.php  of yii-email as below.

 

public function setBody($body = '', $contentType = null, $charset = null) {
		if ($this->view !== null) {
			if (!is_array($body)) $body = array('body'=>$body);
			
			// if Yii::app()->controller doesn't exist create a dummy 
			// controller to render the view (needed in the console app)
			if(isset(Yii::app()->controller))
				$controller = Yii::app()->controller;
			else
				$controller = new CController('YiiMail');
			
			// renderPartial won't work with CConsoleApplication, so use 
			// renderInternal - this requires that we use an actual path to the 
			// view rather than the usual alias
			
                        $basePath = Yii::app()->theme->basePath;
                        if(strpos( $basePath, 'protected')===true){
                             $viewPath = Yii::getPathOfAlias(Yii::app()->mail->viewPath.'.'.$this->view).'.php';       
                        }else{
                        
                             $viewPath = Yii::app()->theme->basePath."/views/mail/".$this->view.".php";
                        }
                        $body = $controller->renderInternal($viewPath, array_merge($body, array('mail'=>$this)), true);	
		}
		return $this->message->setBody($body, $contentType, $charset);
	}

 

     public function sendMail($email)
        {
                $message = new YiiMailMessage;  
  
                $message->from = Yii::app()->params['adminEmail'];    // 送信人  
                $message->addTo($email);                              // 收信人  
                $message->setSubject("订阅成功确认邮件!");
                $coupon = "KAB12345678";
                $message->view = 'email';                             // 邮件模板的文件名(不带后缀PHP)  
                $message->setBody(  
                        array(
                            'email'=>$email,
                            'coupon'=>$coupon
                        
                        ),                       // 传递到模板文件中的参数  
                        'text/html',                                  // 邮件格式  
                        'utf-8'                                       // 邮件编码  
                 ); 
                 $sendmail = Yii::app()->mail->send($message) ;
                
        }

 

来自的Email:<br />   
注册内容如下 <br />  
Email   : &nbsp; <?php echo $email;?>   <br />  
Coupon  : &nbsp; <?php echo $coupon;?>   <br />  

<br />  
<br />  

 

你可能感兴趣的:(template)