I need my system to send simultaneous e-mail to all the emails that are in the bd. Following the code below it only sends the 1st e-mail from the list and still sends the wrong one. Send pro spam. And the msm code I use in the form d contact that sends to inbox perfectly. Ms without the foreach.
public function sendEmail()
{
$emails = $this->emailRepository->EmailByStatus();
$description = 'teste';
$subject = 'teste';
$data = array('description'=>$description, 'subject'=>$subject);
foreach ($emails as $email)
{
$send = Mail::send('email.email-multiple', $data, function($message) use($emails, $description, $subject)
{
$message->to($email)->subject($subject);
$message->from('email@fantasia');
});
}
if(!$send)
{
return 0;
}
return 1;
}
I've tried it like this:
foreach($emails as $email)
{
$message->to($email);
}
Tbm only sends the 1st and wrong tbm. And send it.
What's wrong with the above code?