Sending mail when record inserted

Hey im new to the Yii so sorry if any of questions sound stupid. I created a model called User using the CRUD setup. Basically allows users to register. I was wondering if anyone could tell me how to have that the once the user creates their account, an email is then sent to the administrator (myself) saying a new user has registered.

I would imagine it would go into this function in the controller?


	public function actionCreate()

	{	 

		$model=new User;

		

		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['User']))

		{

			$model->attributes=$_POST['User'];

			if($model->save())

				$this->redirect(array('view','id'=>$model->userId));

		}

		

		

		$this->render('create',array('model'=>$model,'isAdmin'=>!Yii::app()->user->isGuest));

	}

if you want to send a mail after saving a user, you can do it in the User’s afterSave-Method


[...]

if($model->save) { //line 11 in your code

   $model->sendEmail(); //todo

   $this->redirect(array('view','id'=>$model->userId));

}

[...]

afterSave works too