I am new with laravel. I need to send email every day, for example - at 10pm. I know how to send email, but I can't figure out, how to send this email, or lunch my email sending function every day, at specific time.
Asked
Active
Viewed 2,205 times
0
-
possible duplicate of [How to create cron job using PHP?](http://stackoverflow.com/questions/18737407/how-to-create-cron-job-using-php) – Marc B Aug 12 '14 at 15:23
2 Answers
0
This probably isn't as much to do with Laravel as it is a task scheduler.
Check out Crontab for running scripts on a schedule http://crontab.org
For running a job every day at 1pm Monday through Friday.
0 13 * * 1-5 $HOME/scripts/weekday_email.php
Laravel does have a 'later' method for the Mail class, but it won't send email repeatedly.
Mail::later(5, 'emails.welcome', $data, function($message)
{
$message->to('foo@example.com', 'John Smith')->subject('Welcome!');
});

c-griffin
- 2,938
- 1
- 18
- 25
-
Where I need to insert this line 0 13 * * 1-5 $HOME/scripts/weekday_email.php ? – user3921996 Aug 12 '14 at 15:49
-
Youll need to install crontab (on the OS of your server) then at the command line `crontab -e` That will show your scheduled jobs. You can insert the line there. Then after saving, the task will run on its schedule. If you're using managed hosting, your hosting provider may have a GUI for crontab in your control panel. – c-griffin Aug 12 '14 at 15:51
0
The best way to do this in laravel is to build an artisan command, and then call that command via a cron job like so:
1 * * * * /path/to/php /path/to/app/artisan command:name
This allows you to easily test the cron by running the command directly in the terminal. Apart from that, using Laravel artisan commands means that you don't have to worry about autoloading all the classes necessary to execute the command - Laravel will handle that for you.
php artisan command:name

Mike Stivala
- 111
- 7