It Sends Twice Email

public function actionViewforgotpass($id)

{


	$this->layout='/layouts/column2';


	$model=new R('forgotpass');


	$this->render('viewforgotpass',array('model'=>$model));


}


public function actionForgotPassword()


{


  	try


  	{


		$this->pageTitle = "CareerSnaps - Forgot Password";


		$this->layout='main';


		$model=new R('forgotpass');


		$codeGenerator=new codeGenerator;


		$this->performAjaxValidation($model);


		


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


		{


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


		


			if($model->validate())


			{


				$email_sent=new mailer();


				if($_POST['R']['email']!=NULL)


				$email=$_POST['R']['email'];


				


				$model=R::model()->findByAttributes(array('email'=>$email));


				$verification_code=$codeGenerator->generate();


				$model->password=md5($verification_code);


			


				 if($model->save())


				 {


					 $name_portal=CHtml::encode(Yii::app()->name);


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


					  $to_email="abc@yahoo.com";


				  


		


					$forgot_pass="<table width='100%' style='border:5px solid #33CCCC'>


			  <tr bgcolor='#54ACBF'><td> </td></tr>


			  <tr>


			  <td width='594' style='color:#FFFFFF;font-size:32px; margin-bottom:10px;margin-left:10px';>


			<div style='float:left'><img src='".'http://'.Yii::app()->request->getServerName().'/'.Yii::app()->baseUrl."/images/logo.png' /></div><div style='float:right;margin-right:150px;'>    </div></td></tr>


			<tr><td align='center'>


				<table align='center'>


					<tr height='40' style='background:#54ACBF;'><td align='center'>


						<p style='color:#FFFFFF;font-size:16px;font-weight:bold;'>


						Information of changed password.


						</p>


					</td></tr>


					<tr><td><p style='color:#54ACBF;'>Dear Admin</p></td></tr>


					<tr><td>


						<p style='margin-left:20px;color:#54ACBF;'>


						<br>


						We are pleased to in form you that your jobseeker account password has been change.<br /> The details of jobseeker account are given below.  


						</p>


						<p style='color:#54ACBF;margin-left:20px;'> 


						Email : ".$model->email."<br />


						New Password: ".$verification_code."<br />


						</p>


					</td></tr>


					


					


					<br>


					<tr><td align='left'>


						<p style='color:#54ACBF;'>Thanks </p>


					</td></tr>


				</table>


			</td></tr>

</table>";

$email_sent->sentmailjobseeker($to_email,"Information of changed password ",$name_portal,$forgot_pass,$model->email);

var_dump($forgot_pass);exit;

				&#036;this-&gt;redirect(array('viewforgotpass','id'=&gt;&#036;model-&gt;r_id));


				Yii::app()-&gt;end();


				}


			else 


				{


				 &#036;msg = Yii::app()-&gt;getUser()-&gt;setFlash('error','Sorry your  registration is not done due to some internal problame.Please try again. ');


			 


				&#036;this-&gt;redirect(array('site/forgotPassMsg')); 	 


				Yii::app()-&gt;end();


				}	


			}


		}


		&#036;this-&gt;render('forgotpass',array('model'=&gt;&#036;model,));


	}


	catch (Exception &#036;e)


	{


		&#036;model-&gt;addError(NULL, &quot;Error while updating to database&quot;);


	}


}

$email_sent->sentmailjobseeker($to_email,"Information of changed password ",$name_portal,$forgot_pass,$model->email);

The above statement sends mail twice. How to overcome this bug…???

Could you paste here sentmailjobseeker()?

maybe the action is called two times, i.e. if you have ajax form validation turned on it will fire in background when form field is changed and then second time when you submit the form.