This question already has an answer here:

I'm having a strange problem here with crontab. I have set up the crontab correctly to run the cron job as follows:

[user@user ~]$ crontab -e

2 * * * * php usr/share/nginx/html/site/script.php

The script runs, I know this because the script is just a basic test that uses the mail() function to let me know it ran.

But I do not get the e-mail from crontab to let me know the script has ran. I should be getting an output e-mail to the MAILTO address above but I am not. I have even tried with quotes around the address.

There's nothing wrong with Sendmail because otherwise the script wouldn't be able to send an e-mail. There's nothing wrong with the e-mail address either because the mail() code in script.php sends to the same e-mail address.

Technically I could just send the e-mail output myself this way rather than rely on crontab but I know that's not the right way to do it.

Any idea where I am going wrong?

PS. This is a Centos 6.3 server.

marked as duplicate by Jenny D, mdpc, Scott Pack, dunxd, Ward May 20 '13 at 0:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Does your script produce any output to stdout and/or stderr? If not, then cron will not send an email. – Steven Monday Apr 21 '13 at 15:04

What you can do is to remove that MAILTO and then just use a root forwarder.

/root/.forward <- just place your email in there, nothing else. Assuming you are running the cron job as root. You can also do it via /etc/aliases, add the line: user: my@email.com

  • I put my e-mail in that file and removed the MAILTO and still didn't get an e-mail. Haven't tried the second thing you said yet though. – Xenor Apr 21 '13 at 13:28
  • The second solution didn't work either. – Xenor Apr 21 '13 at 13:36

I would check cron log to see whether there is any error reported. Could that be also possible the email is landed in your junk mail folder or recipient mail server rejected the mail for invalid sender name or hostname etc.,?

  • There's nothing in the cron log, just a line saying the command was ran. It's not a junk folder issue either, been checking that and I've also tried directing the output to an e-mail address at a different provider. I did have to edit the mail config to bypass local e-mail check though as shown here serverfault.com/questions/65365/… because php mail(); wasn't working at all on my the server's own domain, I wonder if that broke it. – Xenor Apr 21 '13 at 14:50
  • 1
    Please do a live tail of mail log when your cron runs and see what is happening. You should see where is sendmail relaying to. tail -f /var/log/maillog – antimatter Apr 21 '13 at 15:12
  • 1
    I've no idea why but it started working around 5pm yesterday. I think I did reboot my server late afternoon so maybe that changed something. Or the MAILFROM parameter I added. – Xenor Apr 22 '13 at 20:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.