Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel Supervisor – SMTP issue stopping the code even email is sending through queue

I have supervisor installed to run the code using Laravel queue in background

I am using this things to send an email usually and using SMTP to send an email

But whenever there is any issue with SMTP connection, my code get stopped and firing 500 error even email sending is done through Laravel queue & Supervisor

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How i call an event

event(new ClientRequestSubmitEvent($param1, $param2, $param3);

How ClientRequestSubmitEvent.php looks like

<?php

namespace App\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ClientRequestSubmitEvent implements ShouldQueue
{
    use Dispatchable;
    use InteractsWithSockets;
    use SerializesModels;

    public $userId;
    public $clientId;
    public $requestData;
    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($userId, $clientId, $requestData)
    {
        $this->userId    = $userId;
        $this->clientId  = $clientId;
        $this->requestData = $requestData;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('channel-name');
    }
}

How Listener ClientRequestSubmitListener.php looks like

<?php

namespace App\Listeners;

use App\Events\ClientRequestSubmitEvent;
use App\Mail\ClientRequestSubmitMail;
use App\Models\Client;
use App\Models\ClientHasResource;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Mail;

class ClientRequestSubmitListener implements ShouldQueue
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
    }

    /**
     * Handle the event.
     *
     * @return void
     */
    public function handle(ClientRequestSubmitEvent $event)
    {
        
    Mail::to('test@test.com')->send(new ClientRequestSubmitMail($event));
    }
}

Queue settings in .env is like below

Can anyone help.

Thank You

>Solution :

To make it run on background the Queue connection should be other than sync, eg: database, ‘redisetc; in.env` file

QUEUE_CONNECTION=database
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading