So I'm currently reading Laravel docs about mail queuing, and I've lost the idea, what's the difference between Mail::queue(<params>)
and $this->dispatch(new SendMail(<params>))
. Because in Mail section of Laravel docs the first variant is given, but then it is said "don't forget to configure your queues first". I went to Queue configuring section and there I found that "to add something to queue simply use $this->dispatch($job)
".
So, I've made both variants: one of them looks as follows:
Mail::queue('emails.template',
['name'=>$name, 'msg'=>$message],
function($msg) use ($email){
$msg->to($email)
->subject('Application received');
}
);
And the second, in the same controller, but other method, is just:
$this->dispatch(new SendEmail($name, $message, $email));
In second variant I use job, which handle()
method is the same as code before, just with Mail::send
.
And in both variants the user has to wait the same long time, php artisan queue:listen
remains silent, but the email is sent successfully.
What should I do to clearify my situation? Would highly appreciate any possible help!