我可以在Laravel中使用Mail类发送多封电子邮件。但是,它很慢。因此,我想使用AJAX创建一个进度条,显示在完成之前已发送了多少封电子邮件。
如何找到完成前成功发送的电子邮件数量?
控制器
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';
}
答案 0 :(得分:0)
我可以建议为每个收件人拨打Mail::send
$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
}