在Lumen Jobs中发送邮件时出现BindingResolutionException

时间:2017-02-13 11:54:00

标签: php laravel lumen mailer

发送同步邮件没问题,但是使用Mail :: queue在队列上执行的邮件会引发下一个错误:

Illuminate\Contracts\Container\BindingResolutionException: Target [Swift_Transport] is not instantiable while building [Illuminate\Mail\Mailer, Swift_Mailer]. in /var/www/myapp.dev/vendor/illuminate/container/Container.php:804

当我同步执行电子邮件时,所有内容都已正确配置

1 个答案:

答案 0 :(得分:3)

在Lumen Jobs中发送电子邮件之后遇到了很多麻烦,我将这封电子邮件封装在一个Job中,该邮件与这样的邮件一起使用:

<强> MailDispatcher.php

<?php

namespace App\Jobs;

use Illuminate\Contracts\Mail\Mailable;
use Illuminate\Support\Facades\Mail;

class MailDispatcher extends Job {

    public $mail;

    public function __construct(Mailable $mail) {
        $this->mail = $mail;
    }

    public function handle() {
        Mail::send($this->mail);
    }
}

然后当我想排队邮件......

$mail = new MyMailableMail($user);
dispatch(new MailDispatcher($mail));

它可以正常工作