Why is my cron job not emailing me?
Many of our account holders use cron jobs to perform tasks at specific times. These jobs run at schedulee intervals set within the cron job tool in the cPanel. One of the features of this tool allows you to set an email address so that you receive an email every time the cron job runs. This allows you to keep track of your cron jobs and ensure they are running correctly and as scheduled. However, sometimes we receive support questions that some cron jobs are running but the email is not being recieved. Follow below as we explain how to ensure you get an email for every cron job.
Force an email after cron job is run
- Log into your cPanel.
- From within the main cpanel area, scroll down and find the Advanced category. Click on the cronjobs icon found in that category.
- Now you are in the cron job setup screen. At the top is a Cron Email area where you can enter the email address you want to receive notice every time a cron job runs. Enter your email address here if you do not see an email address next to Current email:
- If you already have an email address in that section and are not receiving an email for one of more of your cron jobs, this is because that the job in question is not producing output. We want to force some sort of output, so from the cron job screen, look at the path of the cron job in question so you know where the script lives. Write down the path if necessary.
- Now that we know where the script is, go back to the main cPanel page and open up the File Manager from within the Files category.
- Once in the File Manager, navigate to your cron script. In our sample, it is simply under the public_html folder and is named testcron.php> Locate your file and highlight it, then click on the Edit icon found in the upper toolbar of the screen. Another popup will appear, simply click on the Edit button there as well to continue to the editor.
- Now that you are in the editor, we want to add a single line to ensure some output is produced. This can be anything from as simple as a space to a sentence. Below is the code we will add to the end of our script:
echo "done";Be sure the line of code is before the php closing tag of ?>.
- Click on the Save Changes button at the top of the screen. Your cron job should now email you every time it runs with the single line of output.
Thank you for your feedback!