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

Time:11-15

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));

CodePudding user response:

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));
  • Related