2013-03-27 53 views
1

搬到新的託管後,我開始有奇怪的問題。PHP郵件()返回路徑問題

PHP郵件()函數只工作,如果我用-f參數添加以下行到php.ini。 (如果我省略-f參數,mail()函數將返回true,但也無可奈何。)

[mail function] 
    sendmail_path = "/usr/sbin/sendmail -t -i -f [email protected]" 

然而,這導致所有消息有以下不良標題:

Return-Path: <[email protected]> 

我已經嘗試向mail()添加第五個參數,但是它沒有效果。

我將非常感謝您的幫助。 在此先感謝!

回答

0

要檢查/更改你的PHP郵件配置:

打開php.ini文件(如果你不知道這一點,見下文)搜索讀取[郵件功能]行添加/更改您的郵件服務器的詳細信息。這可能是本地郵件服務器或您的ISP的郵件服務器。保存/關閉php.ini文件重新啓動你的web服務器

的郵件設置可能是什麼樣子,當你第一次打開php.ini文件的一個例子:

[mail function] 
; For Win32 only. 
SMTP = localhost 
smtp_port = 25 

; For Win32 only. 
;sendmail_from = [email protected] 

; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). 
;sendmail_path = 

附加信息是在呼應phpinfo()你可以查看你的PHP配置細節。你可以通過創建一個.php文件來做到這一點。當你在瀏覽器中運行這個時,你會看到一個完整的PHP配置變量列表。只需搜索包含php.ini和sendmail_path的行即可查看需要使用的值。

另一個想法是,你可以使用ini_set()正確配置您的郵件設置,這樣

下面的代碼添加到您的電子郵件腳本的頂部,如果你的郵件腳本仍然失敗。

// Please specify your Mail Server - Example: mail.example.com. 
ini_set("SMTP","mail.example.com"); 

// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports. 
ini_set("smtp_port","25"); 

// Please specify the return address to use 
ini_set('sendmail_from', '[email protected]'); 
+0

Ini_set修復了問題;謝謝! – SomeCoder 2013-03-27 00:47:51

+0

很高興聽到..歡迎和快樂的編碼.. – 2013-03-27 00:50:47