簡體   English   中英

OS X sendmail的PHP郵件功能

[英]PHP mail function with OS X sendmail

我今天正在編寫大量的文本,因為在遷移到優勝美地之后,PHP郵件功能在我的系統上不再起作用,我想解決這個問題並幫助人們一勞永逸地解決這個問題!

我記得幾個月前,當我使用PHP郵件功能時,會從類似Ellon@MBP-de-Ellon.local之類的東西自動發送電子郵件,但是在過去兩天閱讀了一百頁之后,我沒有找到任何解決方案!

這是我用來了解應在以下配置文件中為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
# user@that.users.mailhost.
#
# 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 = me@example.com

; 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('myemailadress@yahoo.com', 'Subject', 'Message', 'From: ' . $from))
    {
        echo 'Send';
    }
    else
    {
        echo 'Not send';
    }
?>

當我使用MAMP在瀏覽器中加載此頁面時,它會打印“發送”,但是...沒有任何信息通過郵箱...當使用tail -f /var/log/mail.log觀看時,它會打印Operation timed out

這讓我發瘋,您對如何解決這個問題有任何想法嗎? 請原諒我的語言錯誤。 預先感謝您的答復

首先,如果您嘗試使用家庭互聯網連接從MacBook發送電子郵件,則大多數住宅ISP會阻止出站連接上的端口25,這會阻止傳出郵件到達目標服務器(即Gmail的電子郵件傳遞服務器)。

其次,從PHP發送的所有郵件都由Mac的Postfix服務器排隊,並從Mac的Postfix服務器發送。 從終端監控Postfix的日志,然后運行您的PHP腳本。 您將在此處找到特定的錯誤。

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

第三,您可以將本地Postfix服務器配置為針對SMTP服務器(如Gmail)進行身份驗證( Google就是其中之一 ),並使用您的gmail帳戶發送所有電子郵件(或創建類似my-test-acct@gmail.com的虛擬用戶)。 在家里用筆記本電腦測試PHP電子郵件功能時,這始終是我最好的選擇。 通過知名電子郵件服務器的身份驗證還可以防止您的電子郵件被標記為垃圾郵件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM