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

Krishma's avatar

Birthday Email

How to send birthday email directly without using cron job

0 likes
55 replies
drewdan's avatar

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?

1 like
Krishma's avatar

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

Krishma's avatar

For trial purpose i have added the command in kernel.php file.Is the below command correct??

$schedule->command('email:birthday') ->everyMinute();

drewdan's avatar

That looks correct to me, and you have put it in the Schedule method of the App\Console\Kernel.php?

Snapey's avatar

test the command first with php artisan email:birthday

1 like
Krishma's avatar

Yes I have already added that in schedule method of App\Console\kernel.php

Krishma's avatar

I have tested the command php artisan email:birthday and i m getting the output which i hv written in description

Krishma's avatar

can u help me out with the steps which has to be done on server side for running the cron job??

Krishma's avatar

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

drewdan's avatar

as long as the path to your project is correct, that looks good to me.

Krishma's avatar

Then what must be the issue because i m not getting the email through cron job??

drewdan's avatar

Have you setup your email settings correctly? Is there anything appearing in your laravel log?

Krishma's avatar

I have done settings properly but still can u help me with the steps so that i can check it out?

drewdan's avatar

what does your email command look like?

Krishma's avatar

U mean to say the command which i hv written in function handle()?????

drewdan's avatar

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

Krishma's avatar

After running php artisan email:birthday I am getting The Happy Birthday messages were sent successfully!!

guybrush_threepwood's avatar

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.

Krishma's avatar

crontab -e command i hv to run on centos server or on my local cmd???

guybrush_threepwood's avatar

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.

guybrush_threepwood's avatar

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.

Krishma's avatar

Is my app\concole\kernel.php file correct?

guybrush_threepwood's avatar

Yes, your scheduled task definitions are found in App\Console\Kernel.php, inside the schedule() method.

Krishma's avatar

/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??

guybrush_threepwood's avatar

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.

Krishma's avatar

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

Krishma's avatar

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

Next

Please or to participate in this conversation.