2012-08-02 52 views
0

我想發郵件給不同的用戶喜歡我用 問題的電子郵件是,它需要很長的時間循環發送郵件的CakePHP

foreach($users as $user){ 

$this->Email->smtpOptions = array(
           'port' => '25', 
           'timeout' => '30', 
           'host' => 'smtp.topnet.tn', 
          ); 
      Envoie Mail 
      $this->Email->delivery = 'smtp'; 

      $this->Email->reset(); 
      $this->Email->from = $from; 
      $this->Email->to = $To; 
      $this->Email->subject = $subject; 
      $this->set('id_user',$user_id); 
      $this->set('password',$pass); 
      $this->Email->template = 'activcompte'; 

      $this->Email->sendAs = 'both'; 

      $this->Email->send(); 
} 
+1

請記住,如果你要發送到> 1000個用戶,你可能想在http://stackoverflow.com/questions/3905734/how-to-send-100-000-emails-weekly閱讀了郵件羣發是一個不平凡的業務最好留給專業人士 – 2012-08-02 18:04:02

+0

你可以嘗試爲它設置一個cron。每當你的服務器空閒時,請設定時間運行上面的代碼。 – 2012-08-06 04:41:05

回答

1

除了使用foreach循環將郵件發送到所有的用戶一個接一個,簡單地讓所有的users..like的數組...

$Recepients[0] => [email protected] 
    $Recepients[1] => [email protected] 
    $Recepients[2] => [email protected] 
    .... 

and then assign this "$Recepients" array 

$這個 - >的電子郵件 - >於= $受助;