0

So I have this php script that sends an email every time someone visits it the page (opens browser, types in www.example.com/email.php and hits enter). I'm trying to find a way to trigger this on a regular basis with a cron job on a shared host. I can configure the cron to run this command: curl --dump http://www.example.com/email.php but it doesn't send the email.

I've confirmed that the php script works (by manually visiting it) and that the cron job runs (I've set it on the host's control panel to 'send email everytime cron runs'), I just can't get them to work together. Any ideas?

JoeMH
  • 11
  • 3

2 Answers2

1

As long as your web script works by simply opening the page (no user interaction required) you can use wget to mimick a request:

wget -O /tmp/temp_file.html http://www.example.com/email.php
Ben Ashton
  • 1,385
  • 10
  • 15
  • Thanks for the feedback Ben. Now I'm getting this error message: Connecting to www.example.com|xxx.xxx.xxx|:80... connected. HTTP request sent, awaiting response... 403 Forbidden 2012-07-05 15:05:01 ERROR 403: Forbidden. – JoeMH Jul 05 '12 at 19:14
  • Hmm, Sounds like a webserver configuration error. Can you open that webpage in a browser on the same system as the cron? If no gui available from in links/lynx? Also might want to check the error logs on the webserver. – Ben Ashton Jul 05 '12 at 19:20
  • I'm on a shared host, I'm not sure if I can open it from that system. – JoeMH Jul 05 '12 at 21:01
  • Ah, ok, then that's likely why it's not working. If your cronjob is being executed by the same machine as your webserver, you can likely call the php script directly from the cron. example: execute /dir/to/webpath/email.php. Otherwise I am out of ideas, sorry. – Ben Ashton Jul 05 '12 at 21:18
1

Try running the "page" (script) with php so it interprets the file directly.

crontab entry:
* * * * * php your/script/location/email.php >/dev/null 2>&1

rockerest
  • 10,412
  • 3
  • 37
  • 67