【问题标题】:PHP mail function with OS X sendmail带有 OS X sendmail 的 PHP 邮件功能
【发布时间】: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"

ma​​il.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

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

【问题讨论】:

    标签: php macos email sendmail


    【解决方案1】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-23
      • 2017-08-22
      • 1970-01-01
      • 2015-01-23
      • 1970-01-01
      • 2011-01-27
      • 2015-12-10
      • 1970-01-01
      相关资源
      最近更新 更多