In the if(!$validate) block mail function truly runs once.
I'm wondering why In the if($validate) block mail function runs twice !!!???
The problem raise only in Ajax request and in first time that view page loads. after that the if($validate) block runs once, on the other requests if($validate) block truly runs once.
public function  actionCEmail()
{
    $model = $this->loadModel(Yii::app()->user->id);
    $model->scenario = 'CEmail';
    if(isset($_POST['User'])){
        $model->attributes = $_POST['User'];
        $validate=$model->validate();
        if(Yii::app()->request->isAjaxRequest){
            if(!$validate) {
                $to='test@example.ds';
                $subject='test';
                $message='this is test';
                mail($to,$subject,$message);
                Yii::app()->end();
            }
            if($validate){
                $to='test@example.ds';
                $subject='test';
                $message='this is test';
                mail($to,$subject,$message);
                Yii::app()->end();
            }
        }
    }
    if(Yii::app()->request->isAjaxRequest)
        $this->renderPartial('_cemail',array('model'=>$model),false,true);
    else
        $this->render('update',array('model'=>$model,'form'=>'_cemail'));
}
If you need any information tell me put it.
 
    