简体   繁体   中英

Laravel-5 Queueing mail

I'm trying to queue mail using Laravel-5. The code I am using is below. I was expecting the mail to get stored in the database in the 'jobs' table but it just gets sent instantly.

Mail::queue('emails.orderthankyou', ['first_name' => 'My Name'], function ($m) {
    $m->to('me@myemail.com')->subject('Test');
});

Any idea what could be going wrong here?

You probably want to use Mail::later instead.

http://laravel.com/docs/5.1/mail

Mail::later(5, 'emails.orderthankyou', ['first_name' => 'My Name'], function ($m) {
    $m->to('me@myemail.com')->subject('Test');
});

You might be using sync driver ( in config/queue.php ). sync stands for synchronous. Therefore, all jobs are executed instantly.

Delayed Message Queueing

If you wish to delay the delivery of a queued e-mail message, you may use the later method. To get started, simply pass the number of seconds by which you wish to delay the sending of the message as the first argument to the method:

Mail::later(5, 'emails.welcome', $data, function ($message) {
//here 5 is the number of seconds
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM