I'm sending around 7k emails using Laravel and SES. Because I have a limit of 10 emails per second I need to delay when Laravel is sending all the emails in batches of 10 at a time.
Controller
public function queue(){
$invites = Subscriber::all();
$send_at = now();
foreach ($invites as $i => $invite){
if($i % 10 == 0){
$send_at = $send_at->addSeconds(1);
}
SendEmailJob::dispatch($invite)->delay($send_at);
}
dd('sent!');
}
And the Job
public function handle()
{
Mail::to($this->user->email)->send(new InviteMail($this->user));
}
This gave me a timed out error but weirdly it queued all 7k emails and sent them. I'm just curious why I got the error.
Put this function at the starting of your controller function
It will increase the max execution time .