prabin lama
prabin lama

Reputation: 13

Laravel Mail: How can I sent a mail automatically to a user as a message after 1 month of time in laravel

I want to sent mail or notification to user in their gmail account automatically after 1 month. Any suggestion on how to do it in laravel.

For example : when user register a current date then the notification must be sent after 1 month automatically when the time reaches.

I am kind of confused and little suggestion will be very much helpful to me.

Upvotes: 1

Views: 2277

Answers (3)

CodingEra
CodingEra

Reputation: 1807

First you should write a laravel command or any function that handles the task you want to run periodically

Inside file App\Console\Commands\COMMAND_NAME write your code inside handle function

 protected $signature = 'command_call';  # Like 'report:send'
 
 public function handle()
    {
    ......
    ....
    }

then add the command to task scheduler and in the end add make the laravel task scheduling work by adding

Inside file App\Console\Kernel define your command name with path

 protected $commands = ['App\Console\Commands\COMMAND_NAME']

then, Inside schedule function

protected function schedule(Schedule $schedule)
    {
        $schedule->command('report:send')->monthly();
        //for send the user report Every month
    }

Then in your cron job :-

* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1

Upvotes: 1

Milad Khodabandehloo
Milad Khodabandehloo

Reputation: 1977

First you should write a laravel command or any function that handles the task you want to run periodically then add the command to task scheduler and in the end add make the laravel task scheduling work by adding

* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1

to the cronjobs of linux. You can also edit the cron jobs of linux by

crontabs -e

Upvotes: 1

TalESid
TalESid

Reputation: 2514

Use Laravel cronjobs for Task Scheduling, Following tutorial will help you with cron-jobs:

How to set up Cron job in Laravel

Upvotes: 7

Related Questions