Reputation: 220
I have an email array with the variables email
and signup_token
. I want to send the signup_token
to the corresponding email in that array. How can I send multiple emails at once with unique content from an array in Laravel. I am using mailtrap. The array will be big, maybe up to 20-25 arrays in it (with emails and unique signup tokens). As I do it with foreach it goes really slow.
foreach(request('email_list') as $email) {
array_push($emailList, [
'email' => $email,
'signup_token' => md5($email)
]);
Mail::to($email)->send(new RegisterStudent(md5($email)));
}
Upvotes: 1
Views: 556
Reputation: 542
If foreach is slow for you, you can insert them into a database queue, and then you setup a worker that reads from that queue and sends them sequentially in the background.
This way you can scale your application's functionality from the beginning
Upvotes: 2