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

riggerz29's avatar

Vapor scheduled command doesn't fire email but controllers it does

Hi all, I'm having a little trouble sending mail on vapor via a scheduled command. Basically the command is to send reminder emails out about upcoming appointments. Now the command fires the email if I manually run it on Vapor but letting the scheduler do it, does not fire the email, however it updates the database to say its gone.

Curious if anyone else has ran into this?

0 likes
8 replies
Sinnbeck's avatar

Check error log and post the command that sends the mail

riggerz29's avatar

@Sinnbeck thanks for the reply, the command is reminder:bookings

The actual code that sends the mail :

			if($appointment = $item->appointment)
            {
                if(!$appointment->email) {
                    info('Continuing to next reminder');
                    continue;
                }

                Mail::to($appointment->email)->send(new UpcomingTreatment($appointment));

                if(count(Mail::failures()) > 0)
                {
                    $this->info('Error sending reminder to '. $appointment->email.' for booking #'.$appointment->id);
                }
                else
                {
                    $item->reminder_sent = date('Y-m-d H:i:s');
                    $item->save();

                    $this->info('Successfully sent reminder to '. $appointment->email.' for booking #'.$appointment->id);
                }
            }

And the logs from when the command is ran by the scheduler :

[2021-11-04T19:00:17+00:00] Running scheduled command: '/opt/bin/php' 'artisan' reminder:bookings > '/dev/null' 2>&1

Nothing in error logs though.

Sinnbeck's avatar

@riggerz29 so it is in a loop? (continue)

And if this is false, no email is sent?

if(!$appointment->email) { 
riggerz29's avatar

@Sinnbeck Yes sorry it is a loop, should have posted the whole snippet. If there is no email address it will just skip to next iteration. I have created my own appointment ensuring the email is true and this script will work and fire the email if I manually run the command however letting the cron run the command, no email is fired but it will save that the reminder is sent.

Sinnbeck's avatar

@riggerz29 maybe add some logs to check how far it goes

if($appointment = $item->appointment)
            {
            Log::info('yay');
                if(!$appointment->email) {
                   Log::info('NOOOOOO');
                    info('Continuing to next reminder');
                    continue;
                }
                Log::info('FINALLY!'); 
                Mail::to($appointment->email)->send(new UpcomingTreatment($appointment)); 
riggerz29's avatar

@Sinnbeck So adding in the logs both vapor-ui and cloud watch don't show anything when using the Log facade manually running the command logs show using $this->info('log here'). Manually running the command via artisan I get :

Successfully sent reminder to [email protected] for booking #1545

When letting the cron do its thing, I just get this no info logs or anything :

[2021-11-04T20:15:17+00:00] Running scheduled command: '/opt/bin/php' 'artisan' reminder:bookings > '/dev/null' 2>&1
riggerz29's avatar

I have temporary workaround until I have more time to try and resolve this but instead of getting the scheduler to call the artisan command, I have now have the scheduler calling a controller method $schedule->call('App\Http\Controllers\HomeController@sendReminders')->everyFifteenMinutes(); that controller method calls Artisan::call('reminder:bookings'); and the mail gets sent.

Please or to participate in this conversation.