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, thelater
method accepts aDateTime
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));