【问题标题】:PHP mail() not sending mail [duplicate]PHP mail()不发送邮件[重复]
【发布时间】:2017-06-27 17:43:13
【问题描述】:

我目前正在尝试向我的网站添加联系表格,但 postfix 似乎没有发送邮件。这是我的邮件测试脚本:

<?php

ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$from = "test@induce.tech";
$to = "mbergwall2222@gmail.com";
$subject = "PHP Mail Test script";
$message = "This is a test to check the PHP Mail functionality";
$headers = "From:" . $from;
mail($to,$subject,$message, $headers);
echo "Test email sent";
?>

脚本回应了这一点: Test email sent 但是没有邮件被发送。我检查了我的 postfix 邮件日志,这就是我所看到的:

Jun 27 17:09:01 mbergwall2222 postfix/smtp[21196]: A0FDB41107: to=<root@mbergwall2222>, relay=none, delay=0.04, delays=0/0/0.03/0, dsn=5.4.4, status=bounced (Host or domain name not found. Name service error for name=mbergwall2222 type=A: Host not found)
Jun 27 17:09:01 mbergwall2222 postfix/qmgr[1915]: A0FDB41107: removed

看来我的主机名可能有问题。如果我在 SSH 中执行 hostname,它会返回 induce.tech(这是正确的,这是我的服务器所在的域名。这是我的后缀 main.cf:

# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated 
defer_unauth_destination
myhostname = induce.tech
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
inet_protocols = ipv4
local_transport = error:local delivery is disabled
smtp_helo_name = $myhostname.example.com

这是我的两个主机文件:

/etc/hosts

# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
#     /etc/cloud/cloud.cfg or cloud-config from user-data
#
127.0.1.1 induce.tech
127.0.0.1 localhost

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

/etc/主机名

induce.tech

注意:我正在为此 Ubuntu 服务器的控制面板使用服务器试点!

主办方:Digital Ocean

如果有人可以提供帮助,请告诉我!谢谢!

编辑:这是我的 phpinfo(): Pastebin

EDIT2:这是正确的日志文件:

[27-Jun-2017 17:03:50 UTC] mail() on [/srv/users/induce/apps/induce/public/portfolio/php/contact.php:9]: To: mbergwall2222@gmail.com -- Headers: From: contact@induce.tech  Reply-to: mattthefat2222@gmail.com -- Subject: test
[27-Jun-2017 17:05:48 UTC] mail() on [/srv/users/induce/apps/induce/public/portfolio/php/contact.php:9]: To: mbergwall2222@gmail.com -- Headers: From: contact@induce.tech  Reply-to: mattthefat2222@gmail.com -- Subject: Test
[27-Jun-2017 17:08:17 UTC] mail() on [/srv/users/induce/apps/induce/public/portfolio/php/contact.php:10]: To: mbergwall2222@gmail.com -- Headers: From:test@induce.tech -- Subject: PHP Mail Test script
[27-Jun-2017 17:12:12 UTC] mail() on [/srv/users/induce/apps/induce/public/portfolio/php/contact.php:10]: To: mbergwall2222@gmail.com -- Headers: From:test@induce.tech -- Subject: PHP Mail Test script
[27-Jun-2017 17:16:13 UTC] mail() on [/srv/users/induce/apps/induce/public/portfolio/php/contact.php:10]: To: mbergwall2222@gmail.com -- Headers: From:test@induce.tech -- Subject: PHP Mail Test script
[27-Jun-2017 17:16:16 UTC] mail() on [/srv/users/induce/apps/induce/public/portfolio/php/contact.php:10]: To: mbergwall2222@gmail.com -- Headers: From:test@induce.tech -- Subject: PHP Mail Test script
[27-Jun-2017 17:22:23 UTC] mail() on [/srv/users/induce/apps/induce/public/portfolio/php/contact.php:10]: To: mbergwall2222@gmail.com -- Headers: From:test@induce.tech -- Subject: PHP Mail Test script
[27-Jun-2017 17:29:35 UTC] mail() on [/srv/users/induce/apps/induce/public/portfolio/php/contact.php:10]: To: mbergwall2222@gmail.com -- Headers: From:test@induce.tech -- Subject: PHP Mail Test script

EDIT3:这是postconf -n的输出

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
inet_interfaces = all
inet_protocols = all
mailbox_size_limit = 0
mydestination = $myhostname, induce.tech, mbergwall2222, localhost.localdomain, localhost
mydomain = induce.tech
myhostname = induce.tech
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
myorigin = /etc/mailname
readme_directory = no
recipient_delimiter = +
relayhost =
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_use_tls = yes

【问题讨论】:

  • 您确定该消息来自该脚本吗?看起来它正在尝试向 root@mbergwall2222 发送本地电子邮件。
  • 如果您托管在数字海洋上,您应该已经设置好发送 php 电子邮件。给他们的支持团队打电话。
  • 你的php是怎么配置的?检查php.net/manual/en/mail.configuration.php
  • @aynber 我相信是的。这就是日志中的全部内容
  • @datacosmos 已编辑

标签: php linux email ubuntu postfix


【解决方案1】:

由于您没有在 /etc/hostname 中使用 FQDN,因此它与后缀的默认配置以及它如何派生 mydomain 参数的方式相冲突。

myhostname 参数指定运行 Postfix 系统的机器的完全限定域名。 $myhostname 在许多其他 Postfix 配置参数中显示为默认值。

mydomain 参数指定$myhostname 的父域。 由 默认情况下,它是从 $myhostname 中剥离的第一个 部分(除非结果是顶级域)。

相反,如果你在 main.cf 中指定 mydomain,那么 Postfix 将使用 它的值生成一个完全限定的默认值 我的主机名参数。

资源:

因此,例如 www.example.com 的顶级域 (TLD) 将是 com,其中induction.tech 的顶级域 (TLD) 将是 tech

因此,要解决此问题,请将 FQDN 添加到您的 /etc/hosts 文件中,例如 server.induce.tech,然后更新您的 /etc/postfix/main.cf 属性中的 myhostname 参数以匹配。

myhostname = server.induce.tech

否则,您需要在 `/etc/postfix/main.cf 中显式设置 mydomain 参数

mydomain = induce.tech

您可以通过在控制台中运行 postconf -n 查看被覆盖的设置。

【讨论】:

  • 我是否需要在 server.induce.tech 上运行脚本?它现在还发送电子邮件为 example@server.induce.tech
  • 我在 main.cf 中添加了 mydomain = prevent.tech,但仍然没有发送任何内容。
  • 是的,它将以@server.induce.tech 发送电子邮件,除非您指定myorigin 参数以避免与备用电子邮件服务器冲突。请务必在进行更改后重新启动 postfix。
  • 我设置了mydomain=induction.tech,myhostname=induction.tech,重启了postfix,仍然没有邮件发送。
  • 运行 postconf -n 并用结果更新您的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-03-24
  • 1970-01-01
  • 2011-06-05
  • 1970-01-01
  • 2021-12-08
  • 2018-06-10
  • 2012-08-24
相关资源
最近更新 更多