本文介绍了在 PHP 中使用 exec():传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
出于测试目的,假设 input.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():传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!