用于发送邮件的php脚本在通过浏览器执行时无法正常工作,但在从命令行执行时工作正常

时间:2020-12-04 18:14:18

I've written a little PHP script:

我写了一个小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";

    }
?>

the thing that drives me crazy is that when I execute this script from command line it work fine : /usr/bin/php

让我疯狂的是,当我从命令行执行这个脚本时它工作正常:/ usr / bin / php

Array ( [name] => daemon [passwd] => x [uid] => 1 [gid] => 1 [gecos] => daemon [dir] => /usr/sbin [shell] => /bin/sh )

数组([name] =>守护进程[passwd] => x [uid] => 1 [gid] => 1 [gecos] =>守护进程[dir] => / usr / sbin [shell] => / bin / sh )

Mail Sent.

but when I execute it from a remote browser this what I get:

但当我从远程浏览器执行它时,我得到的是:

/usr/bin/php

Array ( [name] => daemon [passwd] => x [uid] => 1 [gid] => 1 [gecos] => daemon [dir] => /usr/sbin [shell] => /bin/sh )

数组([name] =>守护进程[passwd] => x [uid] => 1 [gid] => 1 [gecos] =>守护进程[dir] => / usr / sbin [shell] => / bin / sh )

Mail was'nt Sent

邮件没有发送

any idea? 10x in advance :)

任何想法?提前10x :)

1 个解决方案

#1


1  

Command Line PHP and PHP doesn't use the same php.ini, please check if you have difference between them.

命令行PHP和PHP不使用相同的php.ini,请检查它们之间是否存在差异。

More information on php.ini here

有关php.ini的更多信息,请点击此处

Related question on SO here

关于SO的相关问题在这里

#1


1  

Command Line PHP and PHP doesn't use the same php.ini, please check if you have difference between them.

命令行PHP和PHP不使用相同的php.ini,请检查它们之间是否存在差异。

More information on php.ini here

有关php.ini的更多信息,请点击此处

Related question on SO here

关于SO的相关问题在这里