2011-04-29 134 views
0

我正在開發一個必須發送電子郵件的php腳本。但是我的mail()函數不起作用。我知道我必須以某種方式配置php.ini,並且可能是別的東西,但我不知道究竟是什麼以及如何。順便說一句,我安裝了sendmail。 任何想法?非常感謝。 這是我的代碼。php Mail()函數不起作用

error_reporting(E_ALL); 

$to = '[email protected]'; 

$subject = 'subject'; 

$message = 'text'; 

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=windows-1251' . "\r\n"; 
$headers .= 'To: user <[email protected]>' . "\r\n"; 
$headers .= 'From: server <[email protected]>' . "\r\n"; 

mail($to, $subject, $message, $headers); 

在php.ini我把sendmail_path ="/usr/sbin/sendmail"

PS。我使用Ubuntu

傢伙,在mail.log文件,我得到

Apr 29 16:12:05 IT02 sendmail[7660]: My unqualified host name (IT02) unknown; sleeping for retry 
Apr 29 16:13:05 IT02 sendmail[7660]: unable to qualify my own domain name (IT02) -- using short name 
Apr 29 16:13:05 IT02 sendmail[7660]: p3TED551007660: from=www-data, size=210, class=0, nrcpts=0, msgid=<[email protected]>, bodytype=8BITMIME, [email protected] 

有誰知道這是什麼意思?

+0

顯示一些代碼或至少說你得到什麼錯誤。你使用Linux或Windows的操作系統是哪個? – jimy 2011-04-29 13:13:44

+0

@Kuen,你的問題信息不是很清楚。不,人們可以理解並回答你。改進給出的描述。 – 2011-04-29 13:13:44

+3

它可以假設服務器是Linux和配置指令是一個相對於sendmail – 2011-04-29 13:16:35

回答

6

第一步是確定sendmail的安裝位置。一旦你知道這個路徑,進入你的php.ini。您正在尋找sendmail_path設置。適當地設置它。

如果路徑設置正確,則從mail()正確調用的結果應返回true。 (請注意,返回值只能讓你知道郵件是否傳遞到sendmail [或者在Windows的情況下是SMTP],但不能保證電子郵件用完或sendmail配置正確。)如果它正在返回true,但您仍然沒有收到電子郵件,請檢查您的sendmail配置。

+0

已安裝sendmail。在mail.log我得到:4月29日16:12:05 IT02 sendmail [7660]:我的不合格的主機名(IT02)未知;睡覺重試 Apr 29 16:13:05 IT02 sendmail [7660]:無法限定我自己的域名(IT02) - 使用短名稱 Apr 29 16:13:05 IT02 sendmail [7660]:p3TED551007660:from = www-data,size = 210,class = 0,nrcpts = 0,msgid = <[email protected]>,bodytype = 8BITMIME,relay = www-data @ localhost – Kuen 2011-04-29 14:14:53

+0

因此,您的問題與PHP完全無關。更何況,這是一個非常普遍的問題。 http://www.fedoraforum.org/forum/archive/index.php/t-85365.html – Brad 2011-04-29 14:58:39