sending bulk email using cakePHP

574 views Asked by At

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(['[email protected]' => 'abc']);
        $email->to($mail);
        $email->subject('abc');
        if ($email->send()) {

        } else {

        }
   }
1

There are 1 answers

3
tbrennan On BEST ANSWER

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.