【发布时间】:2016-01-11 06:04:03
【问题描述】:
我今天要写这么一大段文字,因为在迁移到 Yosemite 后,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 在浏览器中加载此页面时,它会打印“Send”,但是……没有任何东西通过邮箱……
使用tail -f /var/log/mail.log 观看时,它会打印Operation timed out。
这让我发疯,你知道如何解决这个问题吗? 请原谅我的语言错误。 提前感谢您的回答。
【问题讨论】: