【问题标题】:php script for sending mail wont work when executed via browser but work fine when executed from command line用于发送邮件的 php 脚本在通过浏览器执行时不起作用,但在从命令行执行时工作正常
【发布时间】:2013-10-29 14:36:25
【问题描述】:

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

数组 ( [名称] => 守护进程 [密码] => x [uid] => 1 [gid] => 1 [gecos] => 守护进程 [目录] => /usr/sbin [外壳] => /bin/sh )

邮件已发送。

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

/usr/bin/php

数组 ( [名称] => 守护进程 [密码] => x [uid] => 1 [gid] => 1 [gecos] => 守护进程 [目录] => /usr/sbin [外壳] => /bin/sh )

邮件未发送

有什么想法吗? 提前 10 倍 :)

【问题讨论】:

    标签: php linux email xampp privileges


    【解决方案1】:

    命令行PHP和PHP不使用相同的php.ini,请检查它们之间是否有区别。

    More information on php.ini here

    Related question on SO here

    【讨论】:

    • 我已经将cli php.ini 复制到lampp 目录,没有任何变化,所有的邮件配置都一样...
    猜你喜欢
    • 1970-01-01
    • 2017-05-07
    • 1970-01-01
    • 2010-10-07
    • 2013-08-25
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    相关资源
    最近更新 更多