Well you'll need some way to check if it's their birthday, that only way I can think of doing that is with a scheduled command. But that's essentially a Cron job. Any reason you don't want to use a Cron job?
Birthday Email
How to send birthday email directly without using cron job
I tried with crob job but its not working...So can u send me steps of schedule command or cron job so that i can verify or test again
https://laravel.com/docs/7.x/scheduling#scheduling-artisan-commands
You need to open Kernel.php and add the artisan command which works out who's has a birthday to send them an email with a schedule, so I'd imagine you'd want to run the command daily
For trial purpose i have added the command in kernel.php file.Is the below command correct??
$schedule->command('email:birthday') ->everyMinute();
That looks correct to me, and you have put it in the Schedule method of the App\Console\Kernel.php?
test the command first with php artisan email:birthday
@snapey good shout!
Yes I have already added that in schedule method of App\Console\kernel.php
I have tested the command php artisan email:birthday and i m getting the output which i hv written in description
can u help me out with the steps which has to be done on server side for running the cron job??
You need to setup one cron job which handles the Laravel scheduler as detailed here: https://laravel.com/docs/7.x/scheduling#introduction
Where are you hosting your website? Most website hosts have help to describe how to add cron jobs
I am hosting it on centos server I have also added cron job using the below command
-
-
-
-
- cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1.
-
-
-
I have assigned the path of my project and after i have tested in localhost by using command
php artisan schedule:run
and I m getting below output
Running scheduled command: "C:\xampp\php\php.exe" "artisan" email:birthday > "NU L" 2>&1
as long as the path to your project is correct, that looks good to me.
Then what must be the issue because i m not getting the email through cron job??
Have you setup your email settings correctly? Is there anything appearing in your laravel log?
I have done settings properly but still can u help me with the steps so that i can check it out?
what does your email command look like?
U mean to say the command which i hv written in function handle()?????
Ther console command which runs when you run php artisan email:birthday
The handle method will probably be fine if you want to show that here
After running php artisan email:birthday I am getting The Happy Birthday messages were sent successfully!!
Something is wrong. If you're running the command on a CentOS server there should never be a reference to a Windows path like C:\xampp\php\php.exe.
Please paste the crontab contents (by running crontab -e) and also the App\Console\Kernel.php schedule function.
crontab -e command i hv to run on centos server or on my local cmd???
You can't run Crontab on a Windows machine (I'm assuming you're using one to develop).
If you want to test your schedule locally you can run php artisan schedule:run manually, or add it to the Windows Task scheduler in order to run every minute.
You should configure crontab on the CentOS server, specifying the correct path to the site's root folder ("path-to-project").
That's why I wanted to see the Kernel's schedule and the crontab entry, to verify that all paths look valid.
For CentOS / Nginx it could look something like this:
/usr/local/bin/php /usr/local/nginx/artisan schedule:run >> /dev/null 2>&1
And for CentOS / Apache something like
/usr/local/bin/php /var/www/html/artisan schedule:run >> /dev/null 2>&1
But it will depend on the server. So need to figure out the correct path to the PHP executable and your artisan command.
Is my app\concole\kernel.php file correct?
Yes, your scheduled task definitions are found in App\Console\Kernel.php, inside the schedule() method.
/home/mylinit/public_html/test.mylinit.com/laravel/app/Console/Commands/BirthdayWishes.php && php artisan schedule:run >> /dev/null 2>&1
Is the above cron tab entry correct??
No, it should be something like:
cd /home/mylinit/public_html/test.mylinit.com/laravel && php artisan schedule:run >> /dev/null 2>&1
You can then test it directly in your server's terminal. First copy and paste the first part:
cd /home/mylinit/public_html/test.mylinit.com/laravel
ls -alh
If you see the artisan command then the first part of your crontab script is OK. Now test the second:
php artisan schedule:run
If you get a "Command not found" then you there is no PHP installed, or it's not referenced on the $PATH variable.
cd /home/mylinit/public_html/test.mylinit.com/laravel && php artisan schedule:run >> /dev/null 2>&1
I tried this path but didnt received any output
cd /home/mylinit/public_html/test.mylinit.com/laravel... This is my server side path but if i want to test using localhost how vl i do that
After running php artisan schedule:run .I m getting the output as Running scheduled command: "C:\xampp\php\php.exe" "artisan" email:birthday > "NU L" 2>&1
Please or to participate in this conversation.