2010-10-12 71 views
2

PHP郵件不工作。沒有錯誤信息。 php.ini顯示錯誤並顯示E_ALL也在。PHP郵件不工作

<?php 
$to = "[email protected]"; 
$subject = "Hi!"; 
$body = "Hi,\n\nHow are you?"; 

$headers = 'From: [email protected]' . "\r\n" . 
    'Reply-To: [email protected]' . "\r\n" . 
    'X-Mailer: PHP/' . phpversion(); 

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

?> 
+0

你怎麼知道它不工作呢? – 2010-10-12 15:46:29

+0

即時消息沒有得到電子郵件 – 2010-10-12 15:47:11

+2

嘗試你的垃圾郵件收件箱... – Shoban 2010-10-12 15:47:58

回答

2

首先,檢查mail()

$sent = mail($to, $subject, $body, $headers); 
if (!$sent) { 
    // there was some error in the message itself, our MTA rejected it or there's an error in MTA's config 
} else { 
    // message was accepted for delivery 
} 

二的返回值,檢查PHP's e-mail settings(請注意,在Linux服務器上的sendmail_path是相關的,而在Windows服務器上它的SMTPsmtp_port)嘗試從另一個應用程序發送電子郵件。第三,根據您使用的SMTP服務器,檢查其日誌中是否有任何警告或錯誤(例如,不能聯繫目標服務器,未連接到網絡等)。第四,如果您確定郵件已成功離開您的網絡,請橫渡您的手指並希望獲得最好的結果。說真的,從那時起你就可以爲你的電子郵件做更多事情 - 如果它沒有交付,你就無法做到。

退房也these tips略有增加您的郵件不會被標記爲垃圾郵件的機會

+0

在linux下忽略SMTP服務器設置。 sendmail的路徑需要正確,然而必須安裝sendmail。 – 2010-10-12 16:05:56

+0

@Alexander Sagen:鏈接的PHP文檔頁面可以解釋這一點。編輯澄清。另外,它可以是任何可以構成sendmail的東西,大多數現代MTA都會從/ usr/sbin/sendmail中爲自己安裝一個符號鏈接。 – Piskvor 2010-10-12 16:09:06

2

謝謝大家這麼多的答覆。這真的很有幫助。這是一個權限問題

drwxrwx --- 2 smmsp smmsp 4096 10月12日12時在/ var /卷軸/ clientmqueue/

以上

drwxrwx --- 2阿帕奇smmsp 4096 10月12日變更12:56/var/spool/clientmqueue/

它工作!