0

I want to send emails to different users like the email I use the problem is that it takes a long time

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();
}
kumar
  • 1,796
  • 2
  • 15
  • 37
dev_symfo
  • 61
  • 2
  • 4
  • 1
    Keep in mind if you are sending to > 1000 users, you may want to read up on http://stackoverflow.com/questions/3905734/how-to-send-100-000-emails-weekly Mass mailing is a non-trivial business best left up to the pros – Ken Li Aug 02 '12 at 18:04
  • You could try to set a cron for it. Whenever your server becomes free, set that time to run the above code. – Arun Jain Aug 06 '12 at 04:41

1 Answers1

1

Instead of using the foreach loop to send the mail to all the users one by one, simply make an array of all the users..like...

  $Recepients[0] => abc@gmail.com
  $Recepients[1] => def@gmail.com
  $Recepients[2] => ghi@gmail.com
  ....

 and then assign this "$Recepients" array

$this->Email->to = $Recepients;

kumar
  • 1,796
  • 2
  • 15
  • 37