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

ya-ya-it's avatar

Sendgrid emails are not delivering sometimes

Hello!

I have an issue with a Sendgrid SMTP. I'm creating a booking system and after each order, a user should receive a booking confirmation with a receipt but for some reason, a lot of users are complaining they don't get it. And every time I'm trying to debug it, I'm getting that email so I even have no idea where to start searching.

Here is my .env setup

// .env 

MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=apikey
MAIL_PASSWORD=API_KEY
MAIL_ENCRYPTION=tls
MAIL_FROM_NAME="Name"
[email protected]

Here is the code that triggers email sending. It happens when the user navigates to "Booking confirmation page"

//app/Http/Controllers/BookingsController.php

try {
               \Mail::to($booking->player_email)->send(new BookingConfirmation($bookingDetails));
               $currentBooking = Bookings::find($booking->current_booking_id);
               $currentBooking->confirm_email_sent_at = Carbon::now()->format('Y-m-d H:i:s');
               $currentBooking->save();
               Log::info('Mail was delivered to ' . $booking->player_email);
} catch (\Exception $e) {
               Log::error('Mail wasn\'t delivered to ' . $booking->player_email . '! Error:' . $e->getMessage());
}

I tried to debug it but I can see only successful messages in my log file. Customers that don't have emails don't appear in my log or at Sendgrid dashboard.

What might be an issue here?

0 likes
3 replies
Snapey's avatar

So they never hit the code you show since the two paths through the code both have logging?

Jaytee's avatar
Jaytee
Best Answer
Level 39

Mailables should ideally be pushed to a queue (changing ->send() to ->queue(), will work, but you'll also need to setup queues so consult the docs) will certainly help.

It could be that it's actually timing out. Jobs that fail (e.g: mail that fails to send) will stay in a failed_jobs table in your database, to which you can use as an indication.

If the job has run successfully, but the user still doesn't receive it, i'd be looking at SendGrid or a different service.

Usually in this case tho, it's because of one or multiple reasons:

  1. Not using queues, therefore the user has to wait for the mail to be sent. Could be a timeout issue, or a connection loss etc

  2. Job failing. Usually jobs will fail if there's an error in the code. You can set the amount of times it will try to run the job and the timeout etc.

  3. The service sending the mail.

  4. User has entered incorrect information like an email address etc.

ya-ya-it's avatar

Sorry for the late reply! Queuing seems to fix the problem! Thank you for a detailed reply!

Please or to participate in this conversation.