我的代码中有一个命令,由cron每天运行,向所有新用户发送电子邮件。它曾经工作正常,但在我将队列驱动程序切换到SQS并将Laravel 5.2升级到5.3后,它开始抛出错误。
InvalidArgumentExceptionvendor/laravel/framework/src/Illuminate/Mail/Mailer.php:379
Invalid view.
我不知道可能导致错误的原因,因为我没有删除视图。此外,当我手动运行该命令时,它不会抛出任何错误。
这是命令代码:
public function handle()
{
$subscriptions = Purchase::where('created_at', '>=', Carbon::now()->subDay())
->groupBy('user_id')
->get();
$bar = $this->output->createProgressBar(count($subscriptions));
foreach ($subscriptions as $subscription) {
$user = $subscription->user;
// if ($user->is_active_customer) {
Mail::to($user)->bcc(env('BCC_RECEIPTS_EMAIL'))->send(new NeedHelp());
// }
$bar->advance();
}
$bar->finish();
$this->info("\nSuccess! " . number_format(count($subscriptions)) . ' emails were sent.');
}
以下是NeedHelp类代码(我已更改此主题的电子邮件和发件人名称):
<?php
namespace App\Mail;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class NeedHelp extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
*/
public function __construct(){
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->subject('Need help?')
->from('default@mail.com', 'Sender')
->view('emails.need-help');
}
}
答案 0 :(得分:0)
我发现了错误。原因是我不小心将两个应用程序连接到同一个队列,这导致他们处理彼此的作业和电子邮件,从而导致此错误。