【发布时间】:2017-04-20 07:44:27
【问题描述】:
我在Ubuntu上使用shell_exec函数调用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/>";
当我在服务器上调用这个页面时,我得到了以下页面:
StringA: Visit STAR WARS™
"/var/www/dead.letter" 1/19
StringB: Visit STAR WARS
我收到了内容为Visit STAR WARS的邮件,却收不到内容为Visit STAR WARS™的邮件。
我从 phpinfo 函数查到,default_charset 是“utf-8”。
如果我直接在 Ubuntu shell 上运行命令"echo Visit STAR WARS™ | mailx -s 'testB' my_email_address@mail.com",我可以得到带有**™**内容的邮件。
谁能帮我解决这个问题,以便 shell_exec 函数可以发送带有特定字符的邮件。
【问题讨论】:
-
shell_exec("echo -n \"$stringA\"| mailx -s 'testA' my_email_address@mail.com"); -
使用escapeshellarg 转义你的特殊字符
-
@Cyclonecode 我测试过,但问题依旧。
-
@hassan,
$stringA=escapeshellarg("Visit STAR WARS™"); $res = shell_exec("echo -n $stringA | mailx -s 'test' tiancheng.li@sony.com");帮不了我,问题仍然存在。 -
shell_exec 的返回值是什么?检查标准错误(通过将标准错误重定向到标准输出)
标签: php shell-exec mailx