0

I want to send emails to 100 users but the requirement is I want a list of successful and failed email ids. I can achieve this by for loop but It is taking time for execution.

I also tried the below code to send bulk emails.

  $subject = "Test Email";
  $email_to = ['dhaval@test','yasin@yopmail.com'];

  $result = Mail::send([], [], function ($message) use($email_to ,$subject){
      $message->to($email_to)
        ->subject($subject);
    });
    
  dd( Mail:: failures()); // return empty array

  dd($result); // return empty array

By sending this way, a function is not returning any failed emails list.

So my question is how to get list of successful/failed email ids in bulk sending Or Is there any alternate way to send bulk emails and get both list.

Yasin Patel
  • 5,624
  • 8
  • 31
  • 53

1 Answers1

-1

use it

$subject = "Test Email";
$emails = ['dhaval@test','yasin@yopmail.com'];
foreach($emails as $email_to){
    $result = Mail::send([], [], function ($message) use($email_to ,$subject){
        $message->to($email_to)->subject($subject);
    });
}
brombeer
  • 8,716
  • 5
  • 21
  • 27