I’ve put together a PHP script that sends some content to a predefined email address and wanted to set up a cron job that would run that PHP script each day. Additionally, I’ve set it up to also send me an email each time the cron runs.
I should mention that this script uses the PHP mail() function to send the email in html format and that I’ve tested if the script works by accessing directly through my browser’s address bar.
The cron command: php /home/myuserid/public_html/projects/jobs/index.php
Surprisingly, when the cron ran, I received the following error message through email:
Use of uninitialized value in concatenation (.) or string at /usr/bin/sendmail line 15.
Content-type: text/html
I’m not even sure where to start looking for the problem, so I need to ask: how do I correctly set up a simple cron job that runs a PHP scripts which sends an email using the mail() function?
I’ve contacted my hosting provider and they’ve changed the cron command themselves to
php /home/myuserid/public_html/projects/jobs/index.php 2> /dev/null, which did the trick.@Matt Whipple suggested a partial fix (i.e. adding
/dev/nullto the command line).