简体   繁体   English

处理队列时未发送 Email laravel

[英]Email are not being send when queue is processed laravel

I am trying to send notification email + database notification to multiple users.我正在尝试向多个用户发送通知 email + 数据库通知。 I am experiencing this strange behavior with laravel queue, it sends database notification perfectly but do not send email.我在使用 laravel 队列时遇到这种奇怪的行为,它完美地发送数据库通知,但不发送 email。 And If I remove the queue it works just fine, both the database notification as well as email are being received.如果我删除队列它工作得很好,数据库通知以及 email 都会收到。

Note: Queue gets processed successfully.注意:队列已成功处理。

Laravel 7 Laravel 7

QUEUE_CONNECTION=database

Notificaion:通知:

<?php

namespace App\Notifications;

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

class CommentOnTask extends Notification implements ShouldQueue
{
    use Queueable;

    private $data;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($data)
    {
        $this->data = $data;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['database', 'mail'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->line('The introduction to the notification.')
                    ->action('Notification Action', url('/'))
                    ->line('Thank you for using our application!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }

    /**
     * Get the database representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toDatabase($notifiable)
    {
        return [
            'body'       => $this->data['body'],
        ];
    }
}

Controller: Controller:

<?php
.
.
.
        $members = $task->users;
        $members = $members->merge($task->followers);

        Notification::send($members, new CommentOnTask($data));

I know this is an old question but I just got notification of this so I thought I should let fellow dev know the issue and solution.我知道这是一个老问题,但我刚刚收到通知,所以我想我应该让开发人员知道这个问题和解决方案。

The problem was with the SMTP server that we were using at that time, hostgator's cpanel emails' SMTP does not work with queue in order words background process, they only work if emails on runtime so we had to change our SMTP and everything started to work properly.问题出在我们当时使用的 SMTP 服务器上, hostgator 的cpanel 电子邮件的 SMTP 不适用于按顺序排列的后台进程,它们只有在运行时的电子邮件才能工作,所以我们必须将 ZC2209ZF92BDE29FE01193 更改为工作适当地。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM