php script called by cronjob is not sending mail

Tino-Designs

Member
Jun 27, 2009
13
0
51
Hi,

I've had this problem for a while now and was not able to solve it.

I setup several cronjobs for testing. i.e. php /home/user/public_html/cron_test2.php

The script gives a quick output and is supposed to send an email. the output is coming through fine (results are sent by cpanel via email).

however the email that the script is suppose to be sedning is never sent. I'm using mail() in php for this, it never works when calle as a cronob.

However when accessing the file directly or entering the same command into the command line mails are coming through fine!!


I also tried to switch from cgi hnadler to apache handler for php. Did not work.

Then I figured out that cronjobs always seemed to call the php script using fastcgi instead of cli regardless of the setting in suexec and PHP

I then figured out that /usr/local/bin/php /home/user/public_html/cron_test2.php would call the file using php cli even when called as cronjob.

But still no emails.


Could anyone please give me a hand here?

Thank you very very much.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,219
463
Hello :)

Have you verified the "crond" service is running on this system? You can check with a command such as:

Code:
service crond status
If it's not running you can restart it via:

Code:
service crond start
Thank you.
 

Tino-Designs

Member
Jun 27, 2009
13
0
51
Hello :)

Have you verified the "crond" service is running on this system? You can check with a command such as:

Code:
service crond status
If it's not running you can restart it via:

Code:
service crond start
Thank you.
Hi yes I already found that suggestion and checked it before. it is working fine. crons in itself are working fine.. It's just email is not being sent.

Well I now figured out that running "wget http://domain.com/urltoscript.php" is seinding mails fine and working but I'm not sure if that is someting we can use without needing to look out for anything. Are there may be security issues involved? Is the content saved on the server and if so where and does it need to be removed after time?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,219
463
It's interesting that using "/usr/local/bin/php -q" in the cron job fails, and "wget" completes successfully. There are not really any additional security issues with using "wget" in this particular instance. You can dump the data to /dev/null if you don't want the file downloaded. EX:

Code:
wget -O/dev/null http://domain
Thank you.
 

Tino-Designs

Member
Jun 27, 2009
13
0
51
It's interesting that using "/usr/local/bin/php -q" in the cron job fails, and "wget" completes successfully. There are not really any additional security issues with using "wget" in this particular instance. You can dump the data to /dev/null if you don't want the file downloaded. EX:

Code:
wget -O/dev/null http://domain
Thank you.
Thank you.

Well againg only email sending fails not the cron php command itself...

oh well your suggestion works fine.

Thanks