Yii-user and Yii-mail:How to render an email from view?

Hi, everyone.

I am using yii-user and yii-mail/mailer…

mailer:http://www.yiiframework.com/extension/mailer/

mail: http://www.yiiframework.com/extension/mail

I know that there is a way to customize the email you send to the user, for example, After you sign up, you can receive an "activation code" from my website via email.

And I want to customize that email now…

Here is the code in my registration controller:


if ($model->save()) {

	$profile->user_id=$model->id;

	$profile->save();

       if (Yii::app()->controller->module->sendActivationMail) {

      $activation_url = $this->createAbsoluteUrl('/user/activation/activation',array(

      "activkey" => $model->activkey, "email" => $model->email));


      UserModule::sendMail($model->email,UserModule::t(

      "Thank you for your registration at {site_name}",array('{site_name}'=>Yii::app()->name)),

       UserModule::t("Please activate your account here {activation_url}",array('{activation_url}'=>$activation_url)));

	}

Those are some codes from the yii-user 's registration controller. (part about email)

So how should I combined the mailer extension with this??


$message = new YiiMailMessage;

$message->view = 'registrationFollowup';

 

//userModel is passed to the view

$message->setBody(array('userModel'=>$userModel), 'text/html');

 

 

$message->addTo($userModel->email);

$message->from = Yii::app()->params['adminEmail'];

Yii::app()->mail->send($message);

Where should I put those codes…?

And how should I modify my view?

Any hints would be very, very helpful.

Thanks!!!!

up

Couple of pointers:

  • Have you set your path to view?
  • Is the view file created? in /protected/view/<mail>/registrationFollowup.php

Tip:

If you intend to alter the code to use yii-mail then simply replace:





UserModule::sendMail($model->email,UserModule::t(

      "Thank you for your registration at {site_name}",array('{site_name}'=>Yii::app()->name)),

       UserModule::t("Please activate your account here {activation_url}",array('{activation_url}'=>$activation_url)));

        }



with your code, but remember to pass the activation url along with your other params, something like:







$message = new YiiMailMessage;

$message->view = 'registrationFollowup';

 

//userModel is passed to the view

$message->setBody(array('model'=>$model, 'activation_url'=>$activation_url), 'text/html');

 

$message->addTo($userModel->email);

$message->from = Yii::app()->params['adminEmail'];

Yii::app()->mail->send($message);




This way you can use your variables in the view