本文介绍了在PHP中使用exec():传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于测试目的,假设输入.PHP看起来像这样

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";
}
?>

exec()调用的sendit.PHP看起来像这样

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);
?>

在浏览器中打开input.PHP时,我收到echo DONE消息,但未发送测试电子邮件.我的代码有什么问题?谢谢.

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.

推荐答案

没有错误信息,我不确定这是否是整个问题,但我将从此开始:

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

$argv读取的参数以空格分隔.以下代码:

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 &

这就是$argv[3] == 'This'$argv[4] == 'is'.

这篇关于在PHP中使用exec():传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 07:01