为什么发送电子邮件使用邮件laravel如果使用shouldqueue不起作用?

时间:2017-11-28 14:45:18

标签: laravel laravel-5 queue laravel-5.3 laravel-mail

我的邮件是这样的:

<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class OrderReceivedMail extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;
    public $order;
    public $store;
    public function __construct($order, $store)
    {
        $this->order = $order;
        $this->store = $store;
        $this->subject('subject');
    }
    public function build()
    {
        $company_email = explode(',',config('app.mail_company'));
        return $this->view('vendor.notifications.mail.email-order-received',['number'=>$this->order->number, 'store_name' => $this->store->name])->bcc($company_email);
    }
}

我的环境是这样的:

BROADCAST_DRIVER=pusher
CACHE_DRIVER=redis
SESSION_DRIVER=file
QUEUE_DRIVER=redis

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

如果代码已执行,则无效。电子邮件发送失败或邮件代码未执行

但如果我删除implements ShouldQueue,它就可以了。电子邮件成功发送

为什么我使用isqueue它不起作用?

1 个答案:

答案 0 :(得分:0)

使用DoWork时,您的电子邮件不会立即发送。您需要按照https://laravel.com/docs/5.5/queues#running-the-queue-worker

中的说明运行队列工作人员ShouldQueue