gpt4 book ai didi

php - 队列中的通知不发送电子邮件

转载 作者:行者123 更新时间:2023-11-29 19:04:06 26 4
gpt4 key购买 nike

我已经使用 Laravel 创建了一个通知,以便当用户提交联系表单时,他将收到一封确认电子邮件。

我还将队列驱动程序设置为数据库,并按照文档所述执行了所有迁移。

因此,我使用 php aritsan make: notification ContactConfirmation Implements ShouldQueue:

创建了通知
    <?php

namespace App\Notifications;

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

class ContactConfirmation extends Notification implements ShouldQueue
{
use Queueable;

public $data;


public function __construct($data)
{
$this->data = $data;
}

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

public function toMail($notifiable)
{
return (new MailMessage)
->subject('Dúvida: '.ucfirst($this->data->subject))
->greeting('Olá '.$this->data->name.'!')
->line('Recebemos a sua mensagem e entraremos em contato assim que possível.')
->line('Obrigado por usar a Mapa do Carro!');
}

public function toArray($notifiable)
{
return [
//
];
}
}

以及在我的 Controller 中调用通知的方法:

    public function sendEmail($data)
{
$user = \App\User::find(1);

$data['name'] = $user->name;
// Mail::to($guest->email)
// ->queue(new ContactConfirmation($guest));

$user->notify(new ContactConfirmation($data));


}

当我提交表单时,会在作业表中创建一条包含通知信息的记录。但是当我运行 php artisan queue: work 命令时,它只会继续处理,直到达到尝试限制。

[2017-04-27 01:05:06] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:06] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:06] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:07] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:07] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:07] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:07] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:08] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:08] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:08] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:08] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:08] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:09] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:09] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:09] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:09] Processing: App\Notifications\ContactConfirmation

最佳答案

您正在将一个数组传递给 ContactConfirmation 类,而 $this->data->subject 是一个对象

关于php - 队列中的通知不发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43647036/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com