Skip to content
Advertisement

Is there a way to delay a Mail by seconds or minutes when sending in laravel 5.8?

I have tried using later and queue then specified the seconds like below but i get an error saying “Only mailables may be queued

Mail::later(5, $email)->send(new PasswordMail($data));

and

Mail::later(5, $email)->queue(new PasswordMail($data));

Here is my code when sending the email

Mail::to($email)->send(new PasswordMail($data));

Advertisement

Answer

The docs clearly describe how to delay mail sending:

Delayed Message Queueing

If you wish to delay the delivery of a queued email message, you may use the later method. As its first argument, the later method accepts a DateTime instance indicating when the message should be sent:

$when = now()->addMinutes(10);

Mail::to($request->user())
    ->cc($moreUsers)
    ->bcc($evenMoreUsers)
    ->later($when, new OrderShipped($order));

So in your case:

Mail::to($email)->later(now()->addMinutes(5), new PasswordMail($data));
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement