2013-10-21 237 views
1

我寫了一個小PHP腳本執行時工作正常發送郵件不會工作:PHP腳本時,通過瀏覽器執行,但在命令行

<?php 
$phpPath = shell_exec("which php"); 

print "$phpPath\n"; 

$uid = posix_getuid(); 
$userinfo = posix_getpwuid($uid); 
print_r($userinfo); 
print "\n"; 


    $to = "[email protected]_company_mail.com"; 
    $subject = "Test mail"; 
    $message = "Hello! This is a simple email message."; 
    $from = "[email protected]"; 
    $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 /斌/ PHP

陣列 ( [名稱] =>守護程序 [passwd中] => X [UID] => 1 [GID] => 1 [gecos] =>守護進程 [dir] =>/usr/sbin [shell] =>/bin/sh )

Mail Sent。

但是當我從遠程瀏覽器執行它這是我得到:

在/ usr/bin中/ PHP

陣列 ( [名] =>守護 [passwd文件] => X [UID] => 1 [GID] => 1 [GECOS] =>守護程序 [DIR] =>/usr/sbin目錄 [外殼] =>/bin/sh的 )

郵件was'nt發送

有什麼想法? 提前10倍:)

回答

相關問題