Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用OS X sendmail的PHP邮件函数_Php_Macos_Email_Sendmail - Fatal编程技术网

使用OS X sendmail的PHP邮件函数

使用OS X sendmail的PHP邮件函数,php,macos,email,sendmail,Php,Macos,Email,Sendmail,我今天写这篇文章是因为迁移到Yosemite后,PHP邮件功能在我的系统上不再工作,我想解决这个问题,帮助人们一劳永逸地解决这个问题 我记得几个月前,当我使用PHP邮件功能时,自动从Ellon@MBP-de Ellon.local,但在过去两天阅读了100页之后,我还没有找到任何解决方案 下面是我用来了解应该在以下配置文件中为myhostname变量赋予什么值的第一个命令: MBP-de-Ellon:~ Ellon$ echo $HOSTNAME MBP-de-Ellon.local 以下是需

我今天写这篇文章是因为迁移到Yosemite后,PHP邮件功能在我的系统上不再工作,我想解决这个问题,帮助人们一劳永逸地解决这个问题

我记得几个月前,当我使用PHP邮件功能时,自动从Ellon@MBP-de Ellon.local,但在过去两天阅读了100页之后,我还没有找到任何解决方案

下面是我用来了解应该在以下配置文件中为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(用于测试)


当我使用MAMP在浏览器中加载此页面时,它会打印“发送”,但。。。邮箱里什么都没有。。。 当使用
tail-f/var/log/mail.log观看时,它会打印
操作超时

这让我发疯了,你知道怎么解决这个问题吗? 请原谅我的语言错误。
提前感谢您的回答

首先,如果您试图使用家庭互联网连接从MacBook发送电子邮件,大多数家庭ISP会阻止出站连接上的端口25,这会阻止传出邮件到达目标服务器(即Gmail的电子邮件传递服务器)

其次,所有从PHP发送的邮件都由Mac的Postfix服务器排队发送。从终端监视Postfix日志,然后运行PHP脚本。您将在那里找到具体的错误

$ tail -f /var/log/mail.log
第三,您可以配置您的本地Postfix服务器,以针对SMTP服务器(如Gmail())进行身份验证,并使用您的Gmail帐户发送所有电子邮件(或创建一个类似my test的虚拟帐户)-acct@gmail.com). 在家里用笔记本电脑测试PHP电子邮件功能时,这始终是我的最佳选择。通过知名的电子邮件服务器进行身份验证还可以防止您的电子邮件被标记为垃圾邮件

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