2016-05-05 38 views
1

發送郵件我想在time.My代碼發送郵件的收件人之一是這樣的:收件人收到兩次相同的郵件,而在警予1.1

$message = new YiiMailMessage; 
$message->view = "mail"; 
$params = array('sendEmail'=>$values); 
$message->subject = $values['subject']; 
$message->setBody($params, 'text/html'); 
$message->from =$values['email_from'] ; 
$message->addTo($values['email_to']); 
if(Yii::app()->mail->send($message)){ 
    Yii::app()->user->setFlash('success','Success sending email. '); 
    $this->redirect(array('mail/admin')); 

}else{ 
    Yii::app()->user->setFlash('error','Error while sending email. '); 
} 

郵件被收件人收到,但相同的郵件接收兩次。

回答

0

也許您每次創建新記錄時都使用創建操作來通知用戶。驗證的Yii ::應用程序() - > MAIL->發($消息)出現在你的行動一次,例如:

public function actionCreate() 
{ 
    $model= new MyModel; 

    // Uncomment the following line if AJAX validation is needed 
    $this->performAjaxValidation($model); 

    if(isset($_POST['SomeForm'])) 
    { 
     $model->attributes=$_POST['SomeForm']; 
     if($model->validate()){ 
     if($model->save()){ 

      $message = new YiiMailMessage; 
      $message->setBody('<h1>mets-blog.com</h1>','text/html'); 
      $message->subject = 'Service'; 
      $message->addTo('[email protected]'); 
      $message->from = '[email protected]' you want 
      Yii::app()->mail->send($message); 

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

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

也許你在你的控制器通過渲染視圖兩次打電話給你的行動。

相關問題