我写了一些 PHP 脚本:
<?php
$phpPath = shell_exec("which php");
print "$phpPath\n";
$uid = posix_getuid();
$userinfo = posix_getpwuid($uid);
print_r($userinfo );
print "\n";
$to = "my_user_name@my_company_mail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "do-not-reply@akamai.com";
$headers = "From:" . $from;
$res = mail($to,$subject,$message,$headers);
print_r(error_get_last());
if($res){
echo "Mail Sent.\n";
}else{
echo "Mail was'nt Sent\n";
}
?>
让我发疯的是,当我从命令行执行这个脚本时,它工作正常:
/usr/bin/php
Array
(
[name] => daemon
[passwd] => x
[uid] => 1
[gid] => 1
[gecos] => daemon
[dir] => /usr/sbin
[shell] => /bin/sh
)
Mail Sent.
但是当我从远程浏览器执行它时,我得到的是:
/usr/bin/php
Array
(
[name] => daemon
[passwd] => x
[uid] => 1
[gid] => 1
[gecos] => daemon
[dir] => /usr/sbin
[shell] => /bin/sh
)
Mail was'nt Sent
有什么想法吗?
最佳答案
Command Line PHP 和 PHP 不使用相同的 php.ini,请检查它们之间是否存在差异。
关于用于发送邮件的 PHP 脚本在通过浏览器执行时不起作用,但在从命令行执行时工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19488819/