1

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

<?php
{
$TO = "[email protected]";
$FROM = "[email protected]";
$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.

2
  • 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? Commented Aug 1, 2011 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. Commented Aug 1, 2011 at 20:06

2 Answers 2

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 [email protected] Yadda This is a test [email protected] > /dev/null &

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.
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.

4 Comments

What do I have to add to write to a file? I have the correct paths.
@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
@johnwhitney when you run your command from command line, does it work? do you get emailed?
I had the patch to PHP wrong. On my host, they require /usr/local/bin/php. Now the code works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.