Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ajithlal's avatar

Queue on server processing, not receiving emails

Hi All,

I'm deploying my project to the server. All my listeners are queued and work fine on local. When I deployed to the server and configured Queue I'm not receiving emails. but processing successfully.

cron job command

* * * * * /usr/local/bin/php /home/username/project/artisan schedule:run >> /dev/null 2>&1

console\Kernel

protected function schedule(Schedule $schedule)
    {
        $schedule->command('queue:work --tries=3')
            ->everyMinute()
            ->withoutOverlapping();
    }

controller

public function pay(Request $request)
    {
        //validating the input

        $booking = Booking::whereId($request->booking_id)
            ->whereUserId(auth('client')->user()->id)
            ->first();

        abort_if(!$booking, 403, 'No bookings found');

        $cartAddOnsTotal = 0;
        $cartTablesTotal = 0;
        $cartServiceTotal = 0;
        $cartFoodArrangementsTotal = 0;
        $subTotal = 0;
        $vat = 0;
        $SubTotalWithVat = 0;
        $balanceAmountToBePaid = 0;
        $grandTotal = 0;
        $deductAmount = 0;

        //calculating the totals

        if ($request->payment_mode == PaymentDetails::PAYMENT_MODE_CASH || $request->payment_mode == PaymentDetails::PAYMENT_MODE_CHEQUE) {
            //creating payment details   

            event(new ClientAdditionalItemsBooked($booking, $cartAddOns, $cartTables, $paymentDetails, $vat, $SubTotalWithVat, $subTotal, $grandTotal));

            return redirect()->route('client.dashboard');
        }
    }

this event has two listeners and I registered it on Event Service provider

protected $listen = [
        ......
        ClientAdditionalItemsBooked::class => [
            NotifyClientAdditionalItemsBooked::class,
            NotifyAdminClientAdditionalItemsBooked::class,
        ],
        .....
    ];

Event Class

class ClientAdditionalItemsBooked
{
    use SerializesModels;

    public $booking;
    public $cartAddOns;
    public $cartTables;
    public $paymentDetails;
    public $vat;
    public $SubTotalWithVat;
    public $subTotal;
    public $grandTotal;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($booking, $cartAddOns, $cartTables, $paymentDetails, $vat, $SubTotalWithVat, $subTotal, $grandTotal)
    {
        $this->booking = $booking;
        $this->cartAddOns = $cartAddOns;
        $this->cartTables = $cartTables;
        $this->paymentDetails = $paymentDetails;
        $this->vat = $vat;
        $this->SubTotalWithVat = $SubTotalWithVat;
        $this->subTotal = $subTotal;
        $this->grandTotal = $grandTotal;
    }
}

Listener

class NotifyAdminClientAdditionalItemsBooked implements ShouldQueue
{
    /**
     * Handle the event.
     *
     * @param  object  $event
     * @return void
     */
    public function handle($event)
    {
        Mail::to(env('ADMIN_EMAIL'))
            ->send(new MailAdminClientAdditionalItemsBooked($event->booking, $event->cartAddOns, $event->cartTables, $event->paymentDetails, $event->vat, $event->SubTotalWithVat, $event->subTotal, $event->grandTotal));
    }
}

Mailable

class MailAdminClientAdditionalItemsBooked extends Mailable
{
    use SerializesModels, Queueable;
    public $booking;
    public $cartAddOns;

    public $cartTables;
    public $paymentDetails;
    public $vat;
    public $SubTotalWithVat;
    public $subTotal;
    public $grandTotal;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($booking, $cartAddOns, $cartTables, $paymentDetails, $vat, $SubTotalWithVat, $subTotal, $grandTotal)
    {
        $this->booking = $booking;
        $this->cartAddOns = $cartAddOns;
        $this->cartTables = $cartTables;
        $this->paymentDetails = $paymentDetails;
        $this->vat = $vat;
        $this->SubTotalWithVat = $SubTotalWithVat;
        $this->subTotal = $subTotal;
        $this->grandTotal = $grandTotal;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->markdown('client.emails.additional_booking.mail_admin_client_additional_items_booked');
    }
}

Edited:

0 likes
11 replies
bugsysha's avatar
bugsysha
Best Answer
Level 61

It does not make sense to run queue:work every minute. Install supervisor as suggested in the docs to run workers.

Not sure why are you showing code from kernel when job processing works. Why didn't you show and explain how you've configured mail sending since that is what is broken?

ajithlal's avatar

@bugsysha I can't install supervisor I'm hosting my website on shared hosting. My mailer working without event. I'm triggering an event when saving data

public function pay(Request $request)
    {
        //validating the input

        $booking = Booking::whereId($request->booking_id)
            ->whereUserId(auth('client')->user()->id)
            ->first();

        abort_if(!$booking, 403, 'No bookings found');

        $cartAddOnsTotal = 0;
        $cartTablesTotal = 0;
        $cartServiceTotal = 0;
        $cartFoodArrangementsTotal = 0;
        $subTotal = 0;
        $vat = 0;
        $SubTotalWithVat = 0;
        $balanceAmountToBePaid = 0;
        $grandTotal = 0;
        $deductAmount = 0;

        //calculating the totals

        if ($request->payment_mode == PaymentDetails::PAYMENT_MODE_CASH || $request->payment_mode == PaymentDetails::PAYMENT_MODE_CHEQUE) {
            //creating payment details   

            event(new ClientAdditionalItemsBooked($booking, $cartAddOns, $cartTables, $paymentDetails, $vat, $SubTotalWithVat, $subTotal, $grandTotal));

            return redirect()->route('client.dashboard');
        }
    }

this event has two listeners and I registered it on Event Service provider

protected $listen = [
        ......
        ClientAdditionalItemsBooked::class => [
            NotifyClientAdditionalItemsBooked::class,
            NotifyAdminClientAdditionalItemsBooked::class,
        ],
        .....
    ];

Event Class

class ClientAdditionalItemsBooked
{
    use SerializesModels;

    public $booking;
    public $cartAddOns;
    public $cartTables;
    public $paymentDetails;
    public $vat;
    public $SubTotalWithVat;
    public $subTotal;
    public $grandTotal;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($booking, $cartAddOns, $cartTables, $paymentDetails, $vat, $SubTotalWithVat, $subTotal, $grandTotal)
    {
        $this->booking = $booking;
        $this->cartAddOns = $cartAddOns;
        $this->cartTables = $cartTables;
        $this->paymentDetails = $paymentDetails;
        $this->vat = $vat;
        $this->SubTotalWithVat = $SubTotalWithVat;
        $this->subTotal = $subTotal;
        $this->grandTotal = $grandTotal;
    }
}

Listener

class NotifyAdminClientAdditionalItemsBooked implements ShouldQueue
{
    /**
     * Handle the event.
     *
     * @param  object  $event
     * @return void
     */
    public function handle($event)
    {
        Mail::to(env('ADMIN_EMAIL'))
            ->send(new MailAdminClientAdditionalItemsBooked($event->booking, $event->cartAddOns, $event->cartTables, $event->paymentDetails, $event->vat, $event->SubTotalWithVat, $event->subTotal, $event->grandTotal));
    }
}

Mailable

class MailAdminClientAdditionalItemsBooked extends Mailable
{
    use SerializesModels, Queueable;
    public $booking;
    public $cartAddOns;

    public $cartTables;
    public $paymentDetails;
    public $vat;
    public $SubTotalWithVat;
    public $subTotal;
    public $grandTotal;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($booking, $cartAddOns, $cartTables, $paymentDetails, $vat, $SubTotalWithVat, $subTotal, $grandTotal)
    {
        $this->booking = $booking;
        $this->cartAddOns = $cartAddOns;
        $this->cartTables = $cartTables;
        $this->paymentDetails = $paymentDetails;
        $this->vat = $vat;
        $this->SubTotalWithVat = $SubTotalWithVat;
        $this->subTotal = $subTotal;
        $this->grandTotal = $grandTotal;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->markdown('client.emails.additional_booking.mail_admin_client_additional_items_booked');
    }
}
bugsysha's avatar

This

but processing successfully.

and this

My mailer working without event.

Are conflicting facts.

ajithlal's avatar

@bugsysha I'm also confused with this. in my controller I've manually added the mailer

public function pay(Request $request)
    {
        //rest of the code

            event(new ClientAdditionalItemsBooked($booking, $cartAddOns, $cartTables, $paymentDetails, $vat, $SubTotalWithVat, $subTotal, $grandTotal)); //didn't received email

Mail::to(env('ADMIN_EMAIL'))
            ->send(new MailAdminClientAdditionalItemsBooked($event->booking, $event->cartAddOns, $event->cartTables, $event->paymentDetails, $event->vat, $event->SubTotalWithVat, $event->subTotal, $event->grandTotal));//got mail

            return redirect()->route('client.dashboard');
        }
    }

but processing successfully.

I'm using the database as my queue_connection.Events listeners are saving to jobs table. After processing the queue, both jobs table and failed_jobs table are empty. That means the jobs are executing.

I can't figure out what is happening

bugsysha's avatar

I never tried to run Laravel on shared hosting. Who knows if your CPanel/provider is somehow blocking you.

ajithlal's avatar

@bugsysha the issue was with the mail configured on the server. I was using server email for sending emails from the server. After updating the mail configuration to Gmail it works fine. I don't know why the server mail is not working.

Thanks for your time.

bugsysha's avatar

the issue was with the mail configured on the server.

That is exactly what I've said/asked in the first post, but guess you've missed it.

bugsysha: Why didn't you show and explain how you've configured mail sending since that is what is broken?

ajithlal's avatar

@bugsysha I thought you are asking about the code that is used for sending the email. Not about the email configuration. :(

bugsysha's avatar

I thought you are asking about the code that is used for sending the email. Not about the email configuration. :(

Nope. Mail configuration. Thanks for the "Best Reply".

Please or to participate in this conversation.