Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
由于某些特定字符,PHP shell_exec失败_Php_Shell Exec_Mailx - Fatal编程技术网

由于某些特定字符,PHP shell_exec失败

由于某些特定字符,PHP shell_exec失败,php,shell-exec,mailx,Php,Shell Exec,Mailx,我正在使用shell\u exec函数调用Ubuntu上的mailx命令发送邮件,但收到错误,因为命令中有特定字符,请查看我下面的代码和结果 <?php $stringA="Visit STAR WARS™"; $stringB="Visit STAR WARS"; echo "StringA:", $stringA, "<br/>"; $res = shell_exec("echo $stringA | mailx -s 'testA' my_email_address@m

我正在使用
shell\u exec
函数调用Ubuntu上的
mailx
命令发送邮件,但收到错误,因为命令中有特定字符,请查看我下面的代码和结果

<?php
$stringA="Visit STAR WARS™";
$stringB="Visit STAR WARS";

echo "StringA:", $stringA, "<br/>";
$res = shell_exec("echo $stringA | mailx -s 'testA' my_email_address@mail.com");
echo $res, "<br/>";

echo "StringB:", $stringB, "<br/>";
$res = shell_exec("echo $stringB | mailx -s 'testB' my_email_address@mail.com");
echo $res, "<br/>";
我收到了内容为“访问星球大战”的邮件,但无法收到内容为“访问星球大战”的邮件™

我从phpinfo函数中进行了检查,默认的字符集是“utf-8”。 如果我运行命令“echo访问星球大战”™ | mailx-s'testB'我的电子邮件_address@mail.com“直接在Ubuntu外壳上,我可以用**™**内容


有人能帮我解决这个问题吗?这样shell_exec函数就可以发送带有特定字符的邮件。

$
[dollar sign]在shell脚本中有特殊含义,因此您不能在命令中传递它

$res = shell_exec("echo '" . $stringA . "' | mailx -s 'testA' my_email_address@mail.com");
最好使用以下方法来逃避您的论点:

$res = shell_exec("echo '" . escapeshellarg($stringA) . "' | mailx -s 'testA' my_email_address@mail.com");

shell_exec(“echo-n\”$stringA\”| mailx-s'testA'我的电子邮件_address@mail.com");用于逃避您的特殊任务chars@Cyclonecode我对它进行了测试,但问题依然存在。@hassan,
$stringA=escapeshellarg(“访问星球大战”)™"); $res=shell_exec(“echo-n$stringA | mailx-s‘test’tiancheng。li@sony.com”;
帮不了我,问题仍然存在。shell_exec的返回值是多少?Chceck stderr(通过将stderr重定向到stdout)有点奇怪。如果我在变量定义中添加escapeshellarg,错误就消失了。
$stringA=escapeshellarg(“访问星球大战”)™”;
,如果没有(
$stringA=“访问星球大战™“;
),问题仍然存在。但是,我无法收到邮件,因为错误已经消失。然后您需要跟踪您的mailx执行情况。谢谢,我通过在
mailx
mailx-S ttycharset=utf-8-S sendcharset=utf-8上设置字符集来解决此问题。
$res = shell_exec("echo '" . escapeshellarg($stringA) . "' | mailx -s 'testA' my_email_address@mail.com");