1

I'm trying to send an email to more then 2000 email ids at a time but It's throwing 502 Bad Gateway error. If I send an email to within 600 mails it's working fine but it's taking 10 minutes time to send to all. please help me if anyone has know about it. Here my code

foreach ($submail as $mail) {         
        $email = new Email();
        $email->template('abc');
        $email->emailFormat('both');
        $email->from(['abc@abc.com' => 'abc']);
        $email->to($mail);
        $email->subject('abc');
        if ($email->send()) {

        } else {

        }
   }
Ashok
  • 184
  • 2
  • 14

1 Answers1

3

It might be better create a queue for your emails, and use a CLI worker to actually send your emails. Check out one of the many plugins:

  1. lorenzo-cakephp-email-queue

  2. nodesagency-cakephp-email-queue

    etc. queueing your emails and using a CLI worker dedicated to sending the emails will open up some extra opportunities like sending the emails at a specific time with cronjobs etc.

Community
  • 1
  • 1
tbrennan
  • 66
  • 3
  • Hi Thanks for your answer.. is there any implementation documentation for first plugin? – Ashok Aug 01 '17 at 09:03
  • Hi, the readme should have all the info you need. [link](https://github.com/lorenzo/cakephp-email-queue/blob/master/README.md) Looks like the repo doesn't have additional documentation available. – tbrennan Aug 01 '17 at 09:07
  • You might also want to look into something like [MailGun](https://mailgun.com), [SendGrid](https://sendgrid.com) or their alternatives. Not every ESP likes mass sending or receiving of e-mail. – Sevvlor Aug 10 '17 at 07:57