The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

php script called by cronjob is not sending mail

Discussion in 'E-mail Discussions' started by Tino-Designs, Aug 12, 2014.

  1. Tino-Designs

    Tino-Designs Member

    Joined:
    Jun 27, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    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.
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,723
    Likes Received:
    660
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
  3. Tino-Designs

    Tino-Designs Member

    Joined:
    Jun 27, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    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?
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,723
    Likes Received:
    660
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
  5. Tino-Designs

    Tino-Designs Member

    Joined:
    Jun 27, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Thank you.

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

    oh well your suggestion works fine.

    Thanks
     
Loading...

Share This Page