1

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
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=myemail@mydomain.co.uk
HOME=/

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.

Xenor
  • 27

2 Answers2

3

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

Emil
  • 53
0

I would check cron and mail 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.,?