How to pass some data to swift mailer

hi there,

In the aftersave() function I use swiftmailer to send a quick email to registrants. What I need to do is pass $this->id from the model that’s just been saved into the swift mail message view. So I can have a line like “hi subscriber number”.$id in the mail.

Could anybody quickly explain to a hack like me how this might be done and how to access a model’s attr from funky places.

Much obliged.


in afterSave() function funky places, you can directly access all model attributes, you insert to db just now, as you write: $this->id.

understood. But how can I pass that value to swiftmailer, or it’s encapsulation mailer and drop it into a message? How to I send it outside of the aftershave() funktion?

I have no experience on swiftmailer,this is my PHPMailer example:

protected function beforeSave() 


    if (parent::beforeSave())


    if ($this->dresult == 0 && $this->dept_id && $this->dcate == 3) 


                 $this->is_case = 1;

// send message to department admin

		 		$email = parse_ini_file(Yii::getPathOfAlias('application').'/config/email.ini');

		 		Yii::app()->mailer->SMTPDebug = false;


				Yii::app()->mailer->CharSet = 'UTF-8';

				Yii::app()->mailer->Host = $email['SMTPServer'];

				Yii::app()->mailer->Port = $email['SMTPPort'];

				Yii::app()->mailer->SMTPAuth = true;

				Yii::app()->mailer->Username = $email['SMTPUser'];

				Yii::app()->mailer->Password = $email['SMTPPassword'];

				Yii::app()->mailer->From = Yii::app()->params['adminEmail'];

				Yii::app()->mailer->FromName = 'Agent: '.Yii::app()->user->name;


				Yii::app()->mailer->Body = $this->dcontent;

				Yii::app()->mailer->Subject = 'Customer consulting';






How to I send it outside of the aftershave() funktion?

call your send mail funciton provided $this arguments in afterSave method place.

[sorry, poor english]

This can be done. Here is an example:

$message = new Message;

$message->view = 'registrationFollowup';


//userModel is passed to the view

$message->setBody(array('someVar'=>$someVar), 'text/html'); //$someVar is now accessible from the view!




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