【问题标题】:Laravel 5.4 Queue Driver says email notification is processed, but email is not sentLaravel 5.4 队列驱动程序说电子邮件通知已处理,但未发送电子邮件
【发布时间】:2019-07-17 23:36:18
【问题描述】:

我正在尝试在触发事件时实现电子邮件通知。当一个事件被触发时,监听器将触发一个电子邮件通知。

当我没有实现队列时发送电子邮件。如果我实施了队列方法,则不会发送电子邮件。

当我运行队列工作者时,它给了我以下输出。但是没有发送电子邮件。

[2019-02-24 11:10:25] Processing: App\Notifications\CustomRequestListener
[2019-02-24 11:10:25] Processed:  App\Notifications\CustomRequestListener

我已经配置了如下的监听器、事件、通知。

听众

 class CustomRequestListener 
 {   
    public function handle(CustomRequestCreated $event)   
    {
      $user->notify(new CustomRequestEmail());   
    } 
 }

通知类

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;

class CustomRequestEmail extends Notification implements ShouldQueue
{
    use Queueable;

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

    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->subject('Test Mail')
            ->view('layout.testmail.template');
    }
}

queue.php

'default' => env('QUEUE_DRIVER', 'database'),

'连接'=> [

    'sync' => [
        'driver' => 'sync',
    ],

    'database' => [
        'driver' => 'database',
        'table' => 'jobs',
        'queue' => 'default',
        'retry_after' => 90,
    ],

.env

QUEUE_DRIVER=database

【问题讨论】:

    标签: laravel queue


    【解决方案1】:

    上面代码中的问题是,shouldQueue 是在通知类上实现的,而它确实需要在监听器上实现。

    下面给出的代码解决了这个问题。

    从通知中移除 ShouldQueue

    class CustomRequestEmail extends Notification
    {
        public function via($notifiable)
        {
            return ['mail'];
        }
    
        public function toMail($notifiable)
        {
            return (new MailMessage)
              ->subject('Test Mail')
              ->view('layout.testmail.template');
        }
    }
    

    将 shouldQueue 添加到监听器

    class CustomRequestListener implements ShouldQueue
     {   
        public function handle(CustomRequestCreated $event)   
        {
          $user->notify(new CustomRequestEmail());   
        } 
     }
    

    【讨论】:

      猜你喜欢
      • 2018-04-20
      • 1970-01-01
      • 2022-08-13
      • 1970-01-01
      • 2017-07-02
      • 1970-01-01
      • 2018-02-01
      • 2019-03-12
      • 1970-01-01
      相关资源
      最近更新 更多