Tjk Posted August 14, 2006 Share Posted August 14, 2006 I've got CRON set up to run this file below every minute... (this is the entire contents of the file)[code=php:0]<?php$to= "myemail@emailprovider.com";$subject= "cron test";$message= "if you receive this cron is working!";mail($to, $subject, $message);?>[/code]Am I missing something about running PHP scripts using CRON or is it a server configuration problem?Help appreciated as always.-Tjk Quote Link to comment Share on other sites More sharing options...
Prismatic Posted August 14, 2006 Share Posted August 14, 2006 What's the problem? Not getting the email? Quote Link to comment Share on other sites More sharing options...
Tjk Posted August 14, 2006 Author Share Posted August 14, 2006 Yeah. The code itself will work when embedded in HTML code but when trying to use CRON to load the pure PHP code itself to mail it to me it doesn't work. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 14, 2006 Share Posted August 14, 2006 Include some error checking then execute your file from the command line so you can see the output. Cron will not return anything, so you can't tell what the error may be. Executing the file from the command line is the same as cron doing it. Quote Link to comment Share on other sites More sharing options...
448191 Posted August 14, 2006 Share Posted August 14, 2006 Set the cronjob to write to file instead. That will tell you if the problem is with mail config or cronjobs.Example:[code]<?phpsetlocale(LC_TIME, "NL_nl");$time = strftime("%H:%M:%S");$fp = fopen('test.txt','w');fwrite($fp,'time: '.$time."\n");?>[/code]Check file afterwards. If everything is as expected, evaluate your mail settings. Quote Link to comment Share on other sites More sharing options...
Tjk Posted August 15, 2006 Author Share Posted August 15, 2006 Out of interest, if I load the script through my web browser should I see a blank page or should I get the error I'm getting which says "Warning: fopen(test.txt): failed to open stream: Permission denied"?Also, I tried it with CRON with no luck. Quote Link to comment Share on other sites More sharing options...
Chetan Posted August 15, 2006 Share Posted August 15, 2006 You need to create a file test.txt Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 15, 2006 Share Posted August 15, 2006 since CRON jobs are not run from a browser, the server doesn't always know what to use to parse the code. try adding this:[code]#!/usr/bin/php -q[/code]to the top of your script (before the opening PHP tag); this line tells the server (linux i believe for this line) what to use to parse the code and where it's located. i don't often use command line, so someone can probably correct my terminology, but this is what i need to add to my CRONs usually. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.