Subject : PHP
Duration : 15 Minuts
Level : Medium / Advanced level PHP Programmer
Language : Html & PHP
Lets go to learn how to set a cron job in cpanel by using PHP script. We are ready to write a simple PHP script for sending email to an email address in every 5 minutes by using creating cron job. First of all, we have to write a PHP email script. I am sending the code in below-
$to = ‘firstname.lastname@example.org’;
$sub = ‘Hello Cron Job!’;
$message = ‘This is for dummy Cron Job.’;
$from = “email@example.com”;
$headers = “From:” . $from;
mail($to, $sub, $message, $headers);
After writing this, I am saving this file named email.php. Now, lets go to our Cpanel. After then, go to public_html and create a new folder test.
Step 1: After successfully loing your Cpanel….
Step 2 : In Advanced tab, you will get the icon entitled Cron jobs. Click on this icon.
Step 3: In Add New Cron, fill up the form. First of all, choose a Common Settings. You can choose anything. Others fields, you can change or may not.
Step 4: Now go to the last field Command and write
php /home/user_name123/public_html/test/cron.php for PHP. [In user_name123, you have to use cpanel user name]
Step 5: Now click Add a New Cron Job button.
Ok, you have completed all the work. Now, wait and see. Your script will be work according to your cron time.
Thanks for ready. Take Care. Bye