This is a working solution, however you will eventually run into problems with this solution. The first may be browser timeout.
Many ISP's have limits on how many emails per hour, and how much data per hour can be sent out before you are black listed. Whats missing from your solution is called throttling. So you don't flood the server. I would suggest you use the queue plugin http://github.com/MSeven/cakephp_queue to first background this work so your browser isn't waiting for it to finish. Once you have the work running in the background now you can take the appropriate amount of time to process your loop and stager the emails being sent so the email server doesn't flag you as flooding. On Aug 4, 1:12 am, fadhli <[email protected]> wrote: > i found the answer. this is my code to send mail to all client. > > function sendall() { > $this->Client->recursive = 0; > $this->set('clients', $this->Client->find('all')); > foreach ($clients as $client) { > $this->Email->reset(); > $this->Email->to = $client['Client']['email']; > $this->Email->subject = 'update request'; > $this->Email->replyTo = '[email protected]'; > $this->Email->from = 'xxxxxxxxxx <a...@xxxxx>'; > $this->Email->template = 'simple_message'; > $this->Email->sendAs = 'html'; > $this->set('client', $client); > $this->Email->send(); > } > if ( $this->Email->send() ) { > $this->Session->setFlash('email been sent'); > } else { > $this->Session->setFlash('email not sent'); > } > $this->redirect(array('action'=>'index')); > } > > On Wed, Aug 4, 2010 at 12:59 AM, fadhli <[email protected]> wrote: > > hi everyone. > > > i want to send email to all my client, the email contains client data, so > > the email different between the client. how to send email to all client at > > ones? i have read > >http://book.cakephp.org/view/1285/Sending-Multiple-Emails-in-a-loopbut i > > don't know how to repeat sending email in my controller. can you give me an > > example? thanks. > > > This is my code for sending an email to one client > > > function _sendmail($id) { > > >> $client = $this->Client->read(null, $id); > > >> $this->Email->to = $client['Client']['email']; > > >> $this->Email->subject = 'update request'; > > >> $this->Email->replyTo = '[email protected]'; > > >> $this->Email->from = 'XXXXX <[email protected]>'; > > >> $this->Email->template = 'simple_message'; > > >> $this->Email->sendAs = 'html'; > > >> $this->set('client', $client); > > >> $this->Email->send(); > > >> } > > >>> function send($id) { > > >> if (!$id) { > > >> $this->Session->setFlash(sprintf(__('Invalid %s', true), 'client')); > > >> $this->redirect(array('action' => 'index')); > > >> } > > >> $this->_sendmail($this->Client->id); > > >> $this->Session->setFlash(sprintf(__('The %s email update > >>> request has been send', true), 'client')); > > >> $this->redirect(array('action' => 'index')); > > >> } Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
