Mail ::队列无法正常工作

时间:2017-02-14 13:16:35

标签: laravel laravel-5.4

我无法在laravel 5.4中排队电子邮件。在之前的laravel 5.3项目中,一切正常。

发送仍然有效:

Mail::send('email.blank', ['title' => 'nice', 'content' => 'message'], function ($message)
        {
            $message->from('a@b.com', 'test');
            $message->to('a@b.com');
        });

队列不起作用:

Mail::queue('email.blank', ['title' => 'nice', 'content' => 'message'], function ($message)
        {
            $message->from('a@b.com', 'test');
            $message->to('a@b.com');
        });

出现以下错误:

InvalidArgumentException in Mailer.php line 314:
Only mailables may be queued.
in Mailer.php line 314
at Mailer->queue('email.blank', array('title' => 'nice', 'content' => 'message'), object(Closure)) in Facade.php line 221
at Facade::__callStatic('queue', array('email.blank', array('title' => 'nice', 'content' => 'message'), object(Closure))) in EmailController.php line 16
at EmailController->mailtest()
at call_user_func_array(array(object(EmailController), 'mailtest'), array()) in Controller.php line 55
at Controller->callAction('mailtest', array()) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(EmailController), 'mailtest') in Route.php line 203
at Route->runController() in Route.php line 160
at Route->run() in Router.php line 559
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 30
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53

我已经通过

创建了队列表
php artisan queue:table
php artisan migrate

并将驱动程序更改为数据库

更新 它看起来像在laravel 5.4中你只能使用mailables排队电子邮件

php artisan make:mail TestMail

在新创建的类中更改构建函数以返回现有视图,例如

public function build()
    {
        return $this->view('email.test');
    }

然后将邮件排队

 Mail::to('a@b.com')->send(new TestMail());

感谢

1 个答案:

答案 0 :(得分:0)

队列电子邮件是使用此脚本

 java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.OutputStream.write(byte[], int, int)' on a null object reference

而不是

Mail::to('a@b.com')->queue(new TestMail());