Php 作业队列中的Laravel电子邮件除同步外不工作
我使用的是Laravel 5.8,我配置了一封电子邮件,其中包含用户下单后发送给他们的发票。 当设置Php 作业队列中的Laravel电子邮件除同步外不工作,php,laravel,laravel-5,Php,Laravel,Laravel 5,我使用的是Laravel 5.8,我配置了一封电子邮件,其中包含用户下单后发送给他们的发票。 当设置QUEUE\u DRIVER=sync时会发送电子邮件,但当我将其设置为redis/database并运行php artisan QUEUE:work redis--trys=5时,会显示队列已被处理 处理:模块\结帐\邮件\发票 已处理:模块\签出\邮件\发票 已成功,失败的\u作业中也没有条目 代码: Modules\Checkout\Jobs\SendInvoiceEmail.php
QUEUE\u DRIVER=sync
时会发送电子邮件,但当我将其设置为redis/database并运行php artisan QUEUE:work redis--trys=5时,会显示队列已被处理
处理:模块\结帐\邮件\发票
已处理:模块\签出\邮件\发票
已成功,失败的\u作业中也没有条目
代码:
Modules\Checkout\Jobs\SendInvoiceEmail.php
class SendInvoiceEmail implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $order;
public function __construct(Order $order)
{
$this->order = $order;
}
public function handle()
{
Mail::to($this->order->customer_email)
->send(new Invoice($this->order));
}
}
class Invoice extends Mailable
{
use Queueable, SerializesModels;
public $order;
public function __construct($order)
{
$this->order = $order;
}
public function build()
{
return $this->subject('New order: ', ['id' => $this->order->id]))
->view("emails.invoice");
}
}
这是Modules\Checkout\Mail\Invoice.php
class SendInvoiceEmail implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $order;
public function __construct(Order $order)
{
$this->order = $order;
}
public function handle()
{
Mail::to($this->order->customer_email)
->send(new Invoice($this->order));
}
}
class Invoice extends Mailable
{
use Queueable, SerializesModels;
public $order;
public function __construct($order)
{
$this->order = $order;
}
public function build()
{
return $this->subject('New order: ', ['id' => $this->order->id]))
->view("emails.invoice");
}
}
然后在创建订单后,我在控制器中调度它
SendInvoiceEmail::dispatch($order)代码>
有人能指出我是否错过了什么,我做错了什么吗
我已经完成了php-artisan-config:cache和clear:cache
重启服务器
如果我在.env中设置QUEUE\u DRIVER=sync
而不是QUEUE\u DRIVER=redis或database
的话,这就像预期的一样,我也遇到了这个问题,并在config/mail.php
文件中添加了一个键来解决它
在mailers['smtp']
中,我添加了local\u domain
等于我的域(example.com
)
原因是Swift Mailer类可以使用此键输入电子邮件的HELO字段。如果您使用QUEUE=sync
框架将使用env文件中的域,但是当您使用不同的队列时,它不会缓存域。这很有趣。谢谢你指出这一点。如果这解决了我的问题,我会试试这个