0

I'm able to send multiple emails using Mail class in Laravel. However, it is slow. Hence, I would like to create a progress bar using AJAX that shows how many emails have been sent before completion.

How do I find out the number emails that are successfully sent before completion?


Controller

private function sendMail($email){ //get saved email model object

    $data = [
        "message_body"=>$email->message
    ];

    $recipients = DB::table('newsletter_subscribers')->lists('email'); //list of multiple email addresses

    Mail::send('emails.body', $data, function($message)use($recipients,$email)
    {
        $message->to($recipients)
            ->subject($email->subject)
            ->from('admin@mail.prettypal.com','prettypal.com');
    });
    return 'success';
}
John Evans Solachuk
  • 1,953
  • 5
  • 31
  • 67

1 Answers1

0

what I can suggest is to call Mail::send for every recipient like this

$number = 0;
foreach ($recipients as $recipient) {
    Mail::send('emails.body', $data, function($message) use($recipient,$email){
        $message->to($recipient)
            ->subject($email->subject)
            ->from('admin@mail.prettypal.com','prettypal.com');
    });
    $number ++; // this is actually the number of sent mails
}
webNeat
  • 2,768
  • 1
  • 20
  • 22
  • Yes, I was initially going towards that direction too but I was afraid it would suffer performance wise...or will it? I was wondering if Laravel or swiftmailer has any method to determine emails sent.. – John Evans Solachuk Aug 27 '14 at 09:42