engrlaravel
4 months ago
599
1
Laravel

Send email to multiple users in loop

Posted 4 months ago by engrlaravel

Hi have below code, i am using to send email to one user, How i can send it to multiple users?

Do i need to clear it after sending to one user?

foreach ($task->users as $user)
{
 $subject = $user->subject;
 $email = $user->email;
 $template_data = "any text";
  Mail::send([], [],
                        function ($message) use ($subject,$email,$template_data) {
                            $message->to($email)
                                ->from('[email protected]')
                                ->subject($subject)
                                ->setBody($template_data, 'text/html');
                        });
}

Please sign in or create an account to participate in this conversation.