1

For testing purposes, let's say input.PHP looks like this

<?php
{
$TO = "joe@net.net";
$FROM = "bob@net.net";
$SUB = "Yadda";
$BODY = "This is a test";
exec("/usr/bin/php /xxx.yyy.net/TESTS/sendit.PHP $TO $SUB $BODY $FROM > /dev/null &");
echo "DONE";
}
?>

And the sendit.PHP which is called by exec() looks like this

<?php
$to      = $argv[1];
$subject = $argv[2];
$message = $argv[3];
$headers = 'From: '.$argv[4]. "\r\n" .
'Reply-To: '.$argv[4]. "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

When I open input.PHP in my browser, I get the echo DONE message, but the test email is not sent. What's wrong with my code? Thank You.

johnwhitney
  • 93
  • 1
  • 3
  • 12
  • 1) If you echo out something in sendit.PHP and put your output to a file, is it there? 2) Why are you doing an exec? Why not just call sendit.PHP directly? – afuzzyllama Aug 01 '11 at 20:04
  • 1
    try writing to a file instead of /dev/null as it will suppress any errors (actually all output) into a black hole, writing to a file will give you more info. Then publish what the file says here. – Travis Pessetto Aug 01 '11 at 20:06

2 Answers2

4

Without error information, I'm not sure if this is the entire problem, but I'd start with this:

Arguments as read by $argv are space-delimited. The following code:

 /usr/bin/php /xxx.yyy.net/TESTS/sendit.PHP $TO $SUB $BODY $FROM > /dev/null &

is executing as follows in your example:

 /usr/bin/php /xxx.yyy.net/TESTS/sendit.PHP joe@net.net Yadda This is a test bob@net.net > /dev/null &

That makes $argv[3] == 'This' and $argv[4] == 'is'.

Chris Hepner
  • 1,552
  • 9
  • 16
  • 1
    i think this could be it. Wonder what he finds. Also note to @Johnwhitney remember to escape characters. So when you have `"Yadda This \"is\" a test"` etc. – Luke Aug 01 '11 at 20:08
1

Without any debugging I don't think anyone will be able to give you an answer.

You have to remember that *nix is case sensitive. So you have to make sure that /xxx.yyy.net/TESTS etc are actually in correct case, spelled correctly.

Also I would suggest not sending everything to /dev/null and maybe to a file. Simply because /usr/bin/php could be using different config (happened to me before) and it didnt work as espected when I ran scripts in crontab.

You need to find out some more info! Check php logs, see what that script gives you when you run it from terminal.

Luke
  • 1,872
  • 20
  • 31
  • What do I have to add to write to a file? I have the correct paths. – johnwhitney Aug 01 '11 at 20:50
  • @joshwhitney Rather than doing `/xxx.yyy.net/TESTS/sendit.PHP $TO $SUB $BODY $FROM > /dev/null` you can probably do something like `/xxx.yyy.net/TESTS/sendit.PHP $TO $SUB $BODY $FROM 2>&1 /var/log/php_emailer.log` so it redirects output to file in `/var/log/php_emailer.log` – Luke Aug 01 '11 at 21:39
  • @johnwhitney when you run your command from command line, does it work? do you get emailed? – Luke Aug 01 '11 at 22:20
  • I had the patch to PHP wrong. On my host, they require /usr/local/bin/php. Now the code works. – johnwhitney Aug 02 '11 at 17:35