首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP mail()不发送邮件

问PHP mail()不发送邮件
EN

Stack Overflow用户
提问于 2017-06-27 17:43:13
回答 1查看 798关注 0票数 0

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

代码语言:javascript
复制
<?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,但没有发送邮件。我查看了我的后缀邮件日志,我看到的是:

代码语言:javascript
复制
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:

代码语言:javascript
复制
# 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/主机

代码语言:javascript
复制
# 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/主机名

代码语言:javascript
复制
induce.tech

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

主机:数字海洋

如果有人能帮忙请告诉我!谢谢!

编辑:这是我的phpinfo(): 巴斯丁

EDIT2:以下是正确的日志文件:

代码语言:javascript
复制
[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

postconf -n EDIT3:这是EDIT3的输出

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2017-06-27 19:22:53

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

myhostname参数指定运行后缀系统的计算机的完全限定的域名。$myhostname在许多其他后缀配置参数中显示为默认值。mydomain参数指定$myhostname的父域。默认情况下,是从$myhostname派生的,方法是去掉第一个部件(除非结果是顶级域)。 相反,如果在main.cf中指定mydomain,则后缀将使用它的值为myhostname参数生成一个完全限定的默认值。

资源:

例如,www.example.com的顶级域将是com,其中induce.tech的TLD为tech。

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

代码语言:javascript
复制
myhostname = server.induce.tech

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

代码语言:javascript
复制
mydomain = induce.tech

可以通过在控制台中运行postconf -n来查看已重写的设置。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44786665

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档