【问题标题】:Laravel mail queue not posting to mailtrapLaravel 邮件队列未发布到邮件陷阱
【发布时间】:2018-02-06 00:48:33
【问题描述】:

我一直试图让 Laravel 的队列工作几个小时,但无济于事,我不知道发生了什么;我认为队列正在工作,因为它们正在发布到数据库,但我不明白的是为什么它们不执行并发布到邮件陷阱。

我已将我的.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:workphp artisan queue:listen 但他们没有在终端上发布任何内容。

更新: 我试过php artisan queue:work --queue=high, emails输出是

Processing: App\Mail\Notification

但它仍然没有向 Mailtrap 发送任何邮件。

【问题讨论】:

  • 您检查日志是否有错误? ./storage/logs/laravel.log

标签: php laravel-5 queue laravel-artisan


【解决方案1】:

您的通知中似乎没有设置public function via()。您需要指定通知的传递方式。

public function via($notifiable)
{
    return ['mail'];
}

此外,通知通常会扩展 Illuminate\Notifications\Notification

没关系,您似乎没有使用内置通知系统。我的猜测是这个问题:

$mailQueue  =   (new SendNotification($contact))
                     ->delay(5);

如果您查看文档,它会将 Carbon 对象传递给延迟。

$job = (new ProcessPodcast($podcast))
  ->delay(Carbon::now()->addMinutes(10));

【讨论】:

  • 我试过 @Pitchinnate 但它仍然无法正常工作 - 我什至创建了一个单独的项目只是为了测试排队但它所做的只是processing 并且从不发送 - 我猜它未能发布但我不知道为什么。我还制作了另一个可邮寄的邮件,以便在排队完成后将邮件发送给不同的用户,但队列会添加到作业数据库中,但在发送其他未排队的邮件时从不发布。
  • 注意:我使用的是可邮寄类而不是通知类,因为它在某种程度上更容易。我还发现我的 SendNotification 类已被处理,但 Mailiable 类仍在处理中,我猜这就是发生失败状态的地方。 [2017-08-29 02:16:28] Processing: App\Jobs\SendNotification[2017-08-29 02:16:28] Processed: App\Jobs\SendNotification[2017-08-29 02:16:28] Processing: App\Mail\Notification
  • 感谢您的建议,但我尝试调试错误消息的是使用 php artisan queue:listen --tries=3 在第三次尝试后发布失败并输出特定错误日志!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-04
  • 1970-01-01
  • 1970-01-01
  • 2023-04-06
  • 2022-08-13
  • 1970-01-01
  • 2023-04-04
相关资源
最近更新 更多