我已经尝试让Laravel的队列工作了几个小时,但是我不知道发生了什么;我认为队列是工作的,因为它们正在发送到数据库中,但我不理解的是,为什么它们不执行并发送到mailtrap。
我已经将我的.env文件设置为database
QUEUE_DRIVER=database
我的控制器:
$mailQueue = (new SendNotification($contact))
->delay(5);
dispatch($mailQueue);我的发送通知作业:
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Mail;
use App\Mail\Notification;
class SendNotification implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $contact;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($contact)
{
$this->contact = $contact;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$notification = (new Notification($contact));
Mail::to('email')
->queue($notification);
}
}最后,我的Mailable:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class Notification extends Mailable
{
use Queueable, SerializesModels;
protected $contact;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($contact)
{
$this->contact = $contact;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('mail.notify')
->with([
'notifyName' => $this->request->name,
'notifySubject' => $this->request->subject
]);
}
}非常基本,但我不明白为什么它不能投递或发送到邮件陷阱;尽管我的Jobs表充满了不投递的队列。
有没有人遇到过这样的问题?如果是这样的话,任何人都知道解决方案是什么-我尝试了php artisan queue:work和php artisan queue:listen,但他们没有在终端上发布任何内容。
更新:我尝试了php artisan queue:work --queue=high, emails,结果是
Processing: App\Mail\Notification
但它仍然没有向Mailtrap发送任何邮件。
发布于 2017-08-29 04:00:45
看起来您的通知中没有设置public function via()。您需要指定您希望如何传递通知。
public function via($notifiable)
{
return ['mail'];
}此外,通知通常会扩展Illuminate\Notifications\Notification。
看起来你并没有使用内置的通知系统。我猜问题出在这里:
$mailQueue = (new SendNotification($contact))
->delay(5);如果您查看文档,它会将一个Carbon对象传递给delay。
$job = (new ProcessPodcast($podcast))
->delay(Carbon::now()->addMinutes(10));https://stackoverflow.com/questions/45924256
复制相似问题