Laravel Vapor Scheduler Not Sending Emails

Published

So I have 3 Commands created to dispatch emails based on certain criteria and have them set to run in Kernel every morning. I get the emailOutputTo notification every morning at the right time without fail but the emails that are supposed to go out never go out. If I run the command on the environment manually it works, I get the email. When I run these on my local machine they work. Before moving to Vapor they were working on my old server. Anyway know what could be the issue?

Here’s an example of a job that’s set to run:

My Command:

    class EmailFreeTrialCode extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'emails:EmailFreeTrialCode';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Email users a free trial promo code if they that have not upgraded after 7 days';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $startDate = Carbon::now()->subDays(7)->startOfDay();
        $endDate = Carbon::now()->subDays(7)->endOfDay();
        $now = Carbon::now()->endOfDay();
        $users = User::whereBetween('created_at', [$startDate, $endDate])->get();

        if (!empty($users) ) {
            foreach ( $users as $user ) {

                $created = Carbon::parse( $user->created_at )->startOfDay();
                $diff    = $created->diffInDays( $now );

                if ( $diff === 7 && !$user->subscription) {
                    //$page = $user->pages()->firstWhere( 'user_id', $user->id );

                    if ($user->email_subscription) {
                        $userData = ( [
                            'username' => $user->username,
                            'userID'   => $user->id,
                        ] );

                        $details = ( [
                            "data" => $userData,
                            "userEmail" => $user->email
                        ]);
                 
                        JobFreeTrialEmail::dispatch($details);
                    }
                }
            }
        }

        return 0;
    }
}

My Job:

    class JobFreeTrialEmail implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $details;

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

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $email = new MailFreeTrial($this->details["data"]);
        Mail::to($this->details["userEmail"])->send($email);

    }
}

Kernel:

    class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        EmailInactiveUsers::class,
        EmailSocialShare::class,
        EmailFreeTrialCode::class,
        TestAddDBRecord::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  IlluminateConsoleSchedulingSchedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        /*$schedule->command('test:TestAddDBRecord')
                 ->timezone('America/New_York')
                 ->everyMinute()
                 ->emailOutputTo('[email protected]');*/

        $schedule->command('emails:EmailInactiveUsers')
                 ->timezone('America/New_York')
                 ->dailyAt('7:00')
                 ->emailOutputTo('[email protected]');

        $schedule->command('emails:EmailSocialShare')
                 ->timezone('America/New_York')
                 ->dailyAt('7:15')
                 ->emailOutputTo('[email protected]');

        $schedule->command('emails:EmailFreeTrialCode')
                 ->timezone('America/New_York')
                 ->dailyAt('7:30')
                 ->emailOutputTo('[email protected]');
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

Any help would be great! Thank you in advance!

Source: Laravel

Published
Categorised as laravel, laravel-scheduler, laravel-vapor Tagged , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq