Welcome to WebmasterWorld Guest from 54.196.238.210

Forum Moderators: bakedjake

Message Too Old, No Replies

Weird cron job issue - works for one user, but not another

     

jdbnd

3:19 pm on Jan 29, 2009 (gmt 0)

5+ Year Member



I have a cronjob set up that runs a relatively simple PHP script that evaluates criteria in a local MySQL table and then sends an email to an external address with the results.

Here's the issue. The script runs fine when I type it in as a URL (www.example.com/folder/script.php) - email delivered fine and everything. And as a cronjob, it runs fine too, when it's tested by my webhost's tech support people (it emails them), but it will NOT email me.

I've tried 3 different email addresses, no dice. Not in the inbox, and not in the spam filter. But when the tech support person uses her personal Yahoo email address, it works fine for her.

Huh? Any ideas?

Thanks,
Joe

mcavic

4:19 pm on Jan 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It sounds like it's looking for an environment variable that doesn't exist on your account. If you have shell access, you can try running it manually to see if it gives any errors. Does the code use $ENV, $_SERVER, etc?

jdbnd

4:25 pm on Jan 29, 2009 (gmt 0)

5+ Year Member



It does use $_SERVER, but then why would it be able to send to one email address, but not to another? The email address is stored in a variable called $to and the email is sent using mail() - all seems pretty straightforward.

I can run it fine manually, but I just run it from a browser, not the shell.

Joe

mcavic

5:50 pm on Jan 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$_SERVER would be a problem for cron. It's possible that the tech has the $_SERVER variables set in her profile for debugging purposes. In that case, it should work for any address when she runs it, but for you it would only work from the URL.

If that's the problem, you may be able to remove it from the script and hard-code the necessary data. Or, you may be able to use curl or wget to call the URL from cron, which would act the same as calling it from your Web browser.

jdbnd

8:24 pm on Jan 29, 2009 (gmt 0)

5+ Year Member



I checked and I was actually wrong about that. It doesn't use $_SERVER anywhere, just $_POST in a couple of places (for constructing the headers of the email) and uses Curl also, as part of the function involves calling an external website.

Joe

jdbnd

8:35 pm on Jan 29, 2009 (gmt 0)

5+ Year Member



Here's the code itself:

include "../config/config.php";
include "../includes/class.db.php";
include "../includes/functions.php";

$db = new db();
$data = $db->get_all_rows('lead_buyer="ed" AND featured_school="1"', 'aa_institution');
$errors = '';

foreach ($data as $school) {
$page = visit($school['form_url']);
if ($page == "NO") {
$errors = $errors.$school['institution_name'].' is blah blah blah';
}
}

if ($errors == '') {
exit();
} else {
$to = 'joe@example.com';
$subj = "blah blah blah";
$mess = "";
$mess = $errors;
$headers = "";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers = "content-type:text/html; charset=UTF-8 \r\n";
$headers = "From: ".$_POST['email']."\r\n";
$headers = "To: ".$to."\r\n";
$headers = "Return-Path: ".$_POST['email'];

$to_return = "-f".$to;
mail($to, $subj, $mess, $headers, "-f".$to);
}

exit();

mcavic

10:00 pm on Jan 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$_POST won't exist unless you're calling it from a POST form. I'm not sure if that would cause the mail to fail, but it can't be good. When calling from cron, you should hard-code the From address.

jdbnd

10:15 pm on Jan 29, 2009 (gmt 0)

5+ Year Member



Did that, still no dice...

I can't figure out why a cronjob would care which email address it was sending results to - since it apparently works fine when the tech puts her own email address in - she waited for it to execute at the schedule time, and it executed, and sent her an email.

If it matters, the web host console I'm using is DirectAdmin.

Argh.

Joe

mcavic

10:26 pm on Jan 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What's the command line that you're using to call the script under cron?

jdbnd

10:28 pm on Jan 29, 2009 (gmt 0)

5+ Year Member



/usr/local/bin/php -f /home/account/domains/example.com/public_html/actions/walker.php

"account" and "example" are plugs - they're called different things in the real command line.

Joe

mcavic

10:32 pm on Jan 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try

cd /home/account/domains/example.com/public_html/actions; /usr/local/bin/php walker.php

Otherwise the includes wouldn't be able to find their files. The tech could be running it this way.

jdbnd

10:40 pm on Jan 29, 2009 (gmt 0)

5+ Year Member



You rule. I wish you all good things.

Joe

mcavic

10:42 pm on Jan 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad to help!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month