2015-10-13 18 views
2

今天我正在寫這個大文本塊,因爲在遷移到優勝美地之後,PHP郵件功能在我的系統上不再工作了,我想解決這個問題並且幫助人們解決這個問題一次和所有!帶有OS X的PHP郵件功能sendmail

我記得,當我使用PHP的郵件功能數個月前,電子郵件來自哪裏的東西自動發送類似[email protected],但閱讀幾百頁的最後兩天後,我還沒有找到任何解決方案!

下面是我用來學習,我應該給什麼價值的MYHOSTNAME變量在配置文件後的第一個命令:

MBP-de-Ellon:~ Ellon$ echo $HOSTNAME 
MBP-de-Ellon.local 

這裏是我的文件需要進行配置的內容(基於教程):

的/ etc/hostconfig中

# This file is going away 

AFPSERVER=-NO- 
AUTHSERVER=-NO- 
TIMESYNC=-NO- 
QTSSERVER=-NO- 
MYSQLCOM=-NO- 
MAILSERVER=-YES- 

/etc/postfix/main.cf中

# INTERNET HOST AND DOMAIN NAMES 
# 
# The myhostname parameter specifies the internet hostname of this 
# mail system. The default is to use the fully-qualified domain name 
# from gethostname(). $myhostname is used as a default value for many 
# other configuration parameters. 
# 
#myhostname = host.domain.tld 
#myhostname = virtual.domain.tld 
myhostname = MBP-de-Ellon.local 

# The mydomain parameter specifies the local internet domain name. 
# The default is to use $myhostname minus the first component. 
# $mydomain is used as a default value for many other configuration 
# parameters. 
# 
#mydomain = domain.tld 

# SENDING MAIL 
# 
# The myorigin parameter specifies the domain that locally-posted 
# mail appears to come from. The default is to append $myhostname, 
# which is fine for small sites. If you run a domain with multiple 
# machines, you should (1) change this to $mydomain and (2) set up 
# a domain-wide alias database that aliases each user to 
# [email protected] 
# 
# For the sake of consistency between sender and recipient addresses, 
# myorigin also specifies the default domain name that is appended 
# to recipient addresses that have no @domain part. 
# 
#myorigin = $myhostname 
#myorigin = $mydomain 

/Applications/MAMP/bin/php/php5.6.10/conf/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"). 
; PERSONNAL NOTE : i've tried the three settings bellow 
;sendmail_path = "env -i /usr/sbin/sendmail -t -i" 
;sendmail_path = "/usr/sbin/sendmail -t -i" 
sendmail_path = "sendmail -t -i" 

mail.php(用於測試)

<?php 
    $from = 'MBP-de-Ellon.local'; 

    if (mail('[email protected]', 'Subject', 'Message', 'From: ' . $from)) 
    { 
     echo 'Send'; 
    } 
    else 
    { 
     echo 'Not send'; 
    } 
?> 

當我使用MA在我的瀏覽器中加載此頁時MP它打印「發送」但是......沒有通過郵箱... 當看與tail -f /var/log/mail.log它打印Operation timed out

這讓我瘋狂,你對如何解決這個問題有什麼想法嗎? 請原諒我的語言錯誤。 在此先感謝您的答案

回答

0

首先,如果您嘗試使用家庭互聯網連接從MacBook發送電子郵件,則大多數住宅ISP會阻止出站連接的端口25,從而阻止外發郵件到達目標服務器(即Gmail的電子郵件傳送服務器)。其次,從PHP發送的所有郵件都排隊並從Mac的Postfix服務器發送。從終端監控Postfix的日誌,然後運行你的PHP腳本。你會在那裏發現特定的錯誤。

$ tail -f /var/log/mail.log 

第三,你可以配置你的本地後綴服務器對如Gmail(Google that one)一個SMTP服務器進行身份驗證,並使用您的Gmail帳戶發送的所有電子郵件(或創建一個像[email protected]虛設)。在我家用筆記本電腦測試PHP電子郵件功能時,這總是我最好的選擇。通過着名的電子郵件服務器進行身份驗證還可以防止您的電子郵件被標記爲垃圾郵件。