最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【未解决】继续调试主页中php发送邮件的功能

PHP crifan 1134浏览 0评论
折腾:
【记录】宝塔Linux面板中搭建Web服务环境
后,继续去调试发送邮件的功能:
然后试了试表单发送邮件也是可以的:
但是邮箱中却没有收到邮件:
难道是:
由于发送人和接收人邮箱是一样的,导致无法发送?
所以去换个邮箱试试
把收件人换成:
$EmailTo = "crifan.li@xxx";
 再去试试
结果发件人换成:
163的
xxx的
都还是不行。
还是抽空再去试试php发送邮件的问题吧。
貌似现在是:
收件人是[email protected],则都是可以发送成功的
收件人是crifan.li@xxx,则都是发送失败的。
难道又是和:
底层服务 /sendmail
或 阿里云的端口 有关系?
抽空去看看
centos php send mail fail
email – PHP mail function not working on Centos server – Stack Overflow
Sendmail fail using php – CentOS
Sending Email via PHP in CentOS 7 using Sendmail – Fasterland
去centos中安装sendmail试试
[root@xxx ~]# yum -y install sendmail
Loaded plugins: fastestmirror
base                                                                                                                                                               | 3.6 kB  00:00:00     
epel                                                                                                                                                               | 4.7 kB  00:00:00     
extras                                                                                                                                                             | 3.4 kB  00:00:00     
updates                                                                                                                                                            | 3.4 kB  00:00:00     
(1/4): extras/7/x86_64/primary_db                                                                                                                                  | 184 kB  00:00:00     
(2/4): epel/x86_64/updateinfo                                                                                                                                      | 903 kB  00:00:00     
(3/4): epel/x86_64/primary_db                                                                                                                                      | 6.3 MB  00:00:00     
(4/4): updates/7/x86_64/primary_db                                                                                                                                 | 6.9 MB  00:00:00     
Determining fastest mirrors
Package sendmail-8.14.7-5.el7.x86_64 already installed and latest version
Nothing to do
果然是不用安装,因为记得之前宝塔Linux面板中是看到过sendmail在运行的:
看起来,或许是端口的问题
去看看阿里云ECS服务器中,是否开放了此处的sendmail正在使用的端口25
果然还没有开放25号端口
所以去参考:
【已解决】阿里云ECS服务器端安全组规则中没有公网的出入规则可以设置
https://help.aliyun.com/document_detail/25471.html
添加进来
但是看到:
添加安全组规则_安全组_用户指南_云服务器 ECS-阿里云
说是:
端口 25 默认受限,无法通过安全组规则打开,但是您可以 申请解封端口 25其他常用端口信息,参考文档:服务器常用端口介绍
ECS 实例常用端口介绍_ECS 实例常用端口介绍_安全组_用户指南_云服务器 ECS-阿里云
TCP 25 端口控制台解封申请_云盾常见问题_安全公告和技术-阿里云
尝试解封端口之前,先去看看是否不用解封,就可以发:
阿里云服务器 centos php 发送邮件失败
解决阿里云服务器mail不能发邮件 – PHP学习网
PHP邮件发送类-博客-云栖社区-阿里云
阿里云服务器 discuz不能发邮件 – 小松博客
解决阿里云mail不能发邮件及sendmail启动慢发信慢的问题 – CSDN博客
Linux服务器下PHPMailer发送邮件失败问题的解决 – CSDN博客
阿里云centos 7 创建postfix服务器,并进行stmp验证,并结合phpmailer进行邮件发送
  去后台看看sendmail服务:
[root@xxx ~]# systemctl restart sendmail
[root@xxx ~]# systemctl status sendmail
[0m sendmail.service - Sendmail Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/sendmail.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2018-03-27 10:08:57 CST; 8s ago
  Process: 9766 ExecStart=/usr/sbin/sendmail -bd $SENDMAIL_OPTS $SENDMAIL_OPTARG (code=exited, status=0/SUCCESS)
  Process: 9760 ExecStartPre=/etc/mail/make aliases (code=exited, status=0/SUCCESS)
  Process: 9758 ExecStartPre=/etc/mail/make (code=exited, status=0/SUCCESS)
Main PID: 9769 (sendmail)
   CGroup: /system.slice/sendmail.service
           9769 sendmail: accepting connections

Mar 27 10:08:56
 
xxx
 
systemd[1]: Starting Sendmail Mail Transport Agent...
Mar 27 10:08:57
 
xxx
 
sendmail[9769]: starting daemon (8.14.7): SMTP+queueing@01:00:00
Mar 27 10:08:57
 
xxx
 
systemd[1]: Started Sendmail Mail Transport Agent.
通过宝塔Linux面板可以看到此处的php中已经是配置好了:
; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
;
 
http://php.net/sendmail-path
sendmail_path = /usr/sbin/sendmail -t -i
猜想:阿里云默认封掉25端口,估计怕服务器乱发垃圾邮件
此处,暂时看看,不去申请解封25端口,是否可以发邮件。
参考:
Linux服务器下PHPMailer发送邮件失败问题的解决 – CSDN博客
去看看用465是否可以。
;
 
http://php.net/smtp-port
;smtp_port = 25
smtp_port = 465
然后:
需要去阿里云开通465端口
但是好像也需要去研究清楚:
【整理】sendmail的参数
期间看到:
php脚本中利用mail函数发送邮件及问题归纳 – CSDN博客
“php中mail函数发送邮件失败问题
      邮箱收不到邮件是因为mail函数发送邮件失败了。php中mail函数是一个自带的发邮件的函数,但是如果你真的要使用mail函数来发邮件那必须是要给你系统安装sendmail组件才可以”
去看看自己此处是否有:cat /var/log/maillog
果然是有的:
[root@xxx ~]# ll /var/log/m
mail/              mail.info          maillog            maillog-20180318   maillog-20180326   messages           messages-20180318  messages-20180326  multi-nic-util/
[root@xxx ~]# ll /var/log/mail*
-rw-r--r--  1 root root     0 Jan 27 15:21 /var/log/mail.info
-rw-------  1 root root   181 Mar 27 10:08 /var/log/maillog
-rw-------. 1 root root 49270 Mar 18 02:58 /var/log/maillog-20180318
-rw-------  1 root root 40418 Mar 20 17:58 /var/log/maillog-20180326

/var/log/mail:
total 4
-rw------- 1 root root 1448 Mar 20 17:58 statistics
[root@xxx ~]# cat /var/log/maillog-20180318
Mar 13 11:49:29 izwz98mcugzor5bbz6tntpz sendmail[950]: My unqualified host name (izwz98mcugzor5bbz6tntpz) unknown; sleeping for retry
Mar 13 11:50:29 izwz98mcugzor5bbz6tntpz sendmail[950]: unable to qualify my own domain name (izwz98mcugzor5bbz6tntpz) -- using short name
Mar 13 11:50:29 izwz98mcugzor5bbz6tntpz sendmail[10785]: starting daemon (8.14.7): SMTP+queueing@01:00:00
Mar 13 11:50:29 izwz98mcugzor5bbz6tntpz sm-msp-queue[10800]: starting daemon (8.14.7): queueing@01:00:00
Mar 14 18:00:19 xxx sendmail[1198]: starting daemon (8.14.7): SMTP+queueing@01:00:00
Mar 14 18:00:20 xxx sm-msp-queue[1235]: starting daemon (8.14.7): queueing@01:00:00
Mar 15 16:28:11 xxx sendmail[27279]: w2F8SBhc027279: from=www, size=310, class=0, nrcpts=1, msgid=<
201803150828.w2F8SBhc027279@xxx
>, relay=www@localhost
Mar 15 16:28:12 xxx sendmail[27281]: w2F8SBM2027281: from=<
www@xxx
>, size=528, class=0, nrcpts=1, msgid=<
201803150828.w2F8SBhc027279@xxx
>, proto=ESMTP, daemon=MTA, relay=localhost [127.0.0.1]
Mar 15 16:28:12 xxx sendmail[27279]: w2F8SBhc027279: to=
[email protected]
, ctladdr=www (1000/1000), delay=00:00:01, xdelay=00:00:01, mailer=relay, pri=30310, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (w2F8SBM2027281 Message accepted for delivery)
Mar 15 16:34:38 xxx sendmail[27299]: w2F8YctM027299: from=www, size=355, class=0, nrcpts=1, msgid=<
201803150834.w2F8YctM027299@xxx
>, relay=www@localhost
Mar 15 16:34:38 xxx sendmail[27300]: w2F8Yc25027300: from=<
www@xxx
>, size=573, class=0, nrcpts=1, msgid=<
201803150834.w2F8YctM027299@xxx
>, proto=ESMTP, daemon=MTA, relay=localhost [127.0.0.1]
Mar 15 16:34:38 xxx sendmail[27299]: w2F8YctM027299: to=
[email protected]
, ctladdr=www (1000/1000), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30355, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (w2F8Yc25027300 Message accepted for delivery)
然后也看到了别人提到的:
sendmail[950]: My unqualified host name (izwz98mcugzor5bbz6tntpz) unknown; sleeping for retry
sendmail My unqualified host name unknown sleeping for retry
sendmail – “My unqualified host name (foo.bar) unknown” Problem – Server Fault
Sendmail: “unqualified hostname unknown; sleeping for retry unqualified hostname – LinuxConfig.org
https://linuxconfig.org/sendmail-unqualified-hostname-unknown-sleeping-for-retry-unqualified-hostname
ubuntu – Sendmail SMTP “My unqualified hostname” and “My unqualified domain name” – Unix & Linux Stack Exchange
此处自己的是:
[root@xxx ~]# cat /etc/host
host.conf    hostname     hosts        hosts.allow  hosts.deny
[root@xxx ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
想要加上自己的hostname
但是需要搞清楚,如何查到自己当前的hostname
Linux系统下sendmail发送邮件失败的问题-云计算与大数据-51CTO博客
还提到了:
hosts.allow
去看看:
[root@xxx ~]# cat /etc/hosts.allow
#
# hosts.allow   This file contains access rules which are used to
#               allow or deny connections to network services that
#               either use the tcp_wrappers library or that have been
#               started through a tcp_wrappers-enabled xinetd.
#
#               See 'man 5 hosts_options' and 'man 5 hosts_access'
#               for information on rule syntax.
#               See 'man tcpd' for information on tcp_wrappers
#
暂时不去动hosts.allow,需要的话再去改修改。
看到了:
3.可以用hostanme 命令临时修改主机名,hostname aa.com;
所以去:
[root@xxx ~]# hostname
xxx
所以把自己的hostname加上:
[root@xxx ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
 
xxx
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
然后再去发送邮件试试
对应的2个log:
[root@xxx ~]# cat /var/log/maillog
Mar 27 10:08:57 xxx sendmail[9769]: starting daemon (8.14.7): SMTP+queueing@01:00:00
Mar 27 10:08:58 xxx sm-msp-queue[9783]: starting daemon (8.14.7): queueing@01:00:00
Mar 27 10:51:42 xxx sendmail[13051]: w2R2pgRs013051: from=www, size=316, class=0, nrcpts=1, msgid=<
201803270251.w2R2pgRs013051@xxx
>, relay=www@localhost
Mar 27 10:51:42 xxx sendmail[13052]: w2R2pgJQ013052: <
crifan.li@xxx
>... User unknown
Mar 27 10:51:42 xxx sendmail[13051]: w2R2pgRs013051: to=
crifan.li@xxx
, ctladdr=www (1000/1000), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30316, relay=[127.0.0.1] [127.0.0.1], dsn=5.1.1, stat=User unknown
Mar 27 10:51:42 xxx sendmail[13052]: w2R2pgJQ013052: from=<
www@xxx
>, size=316, class=0, nrcpts=0, proto=ESMTP, daemon=MTA, relay=localhost [127.0.0.1]
Mar 27 10:51:42 xxx sendmail[13051]: w2R2pgRs013051: w2R2pgRt013051: DSN: User unknown
Mar 27 10:51:42 xxx sendmail[13052]: w2R2pgJS013052: from=<>, size=2263, class=0, nrcpts=1, msgid=<
201803270251.w2R2pgRt013051@xxx
>, bodytype=8BITMIME, proto=ESMTP, daemon=MTA, relay=localhost [127.0.0.1]
Mar 27 10:51:42 xxx sendmail[13051]: w2R2pgRt013051: to=www, delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=31340, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (w2R2pgJS013052 Message accepted for delivery)
Mar 27 10:51:42 xxx sendmail[13053]: w2R2pgJS013052: to=root, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=32443, dsn=2.0.0, stat=Sent
Mar 27 10:54:22 xxx sendmail[13082]: w2R2sMuJ013082: from=www, size=303, class=0, nrcpts=1, msgid=<
201803270254.w2R2sMuJ013082@xxx
>, relay=www@localhost
Mar 27 10:54:22 xxx sendmail[13083]: w2R2sMnK013083: <
crifan.li@xxx
>... User unknown
Mar 27 10:54:22 xxx sendmail[13082]: w2R2sMuJ013082: to=
crifan.li@xxx
, ctladdr=www (1000/1000), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30303, relay=[127.0.0.1] [127.0.0.1], dsn=5.1.1, stat=User unknown
Mar 27 10:54:22 xxx sendmail[13083]: w2R2sMnK013083: from=<
www@xxx
>, size=303, class=0, nrcpts=0, proto=ESMTP, daemon=MTA, relay=localhost [127.0.0.1]
Mar 27 10:54:22 xxx sendmail[13082]: w2R2sMuJ013082: w2R2sMuK013082: DSN: User unknown
Mar 27 10:54:22 xxx sendmail[13083]: w2R2sMnM013083: from=<>, size=2250, class=0, nrcpts=1, msgid=<
201803270254.w2R2sMuK013082@xxx
>, bodytype=8BITMIME, proto=ESMTP, daemon=MTA, relay=localhost [127.0.0.1]
Mar 27 10:54:22 xxx sendmail[13082]: w2R2sMuK013082: to=www, delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=31327, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (w2R2sMnM013083 Message accepted for delivery)
Mar 27 10:54:22 xxx sendmail[13084]: w2R2sMnM013083: to=root, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=32430, dsn=2.0.0, stat=Sent
显示都发送成功了,但是实际上没有发送成。
不过至少没有提示hostname有问题了。
估计是端口限制的问题。
不过还是先去试试,添加465端口:
再去重启服务器:
然后再去试试邮件发送
不过发现,sendmail还是监听25端口,而不是465端口啊:
不管,去试试再说
结果还是失败
算了,去申请开通25端口吧
先去改回25端口
再去申请开通25端口:
【记录】阿里云服务器中申请解封发送邮件的25号端口
不过看到相关的帖子:
使用SSL加密465端口发信样例及Demo_安全问题_常见问题_云虚拟主机-阿里云
感觉是:
把25换成465的话,
php代码从mail()换成PHPMailer
设置合适的ssl的参数后,应该也是可以用来发送邮件的
在等待期间,再去参考:
Sending Email via PHP in CentOS 7 using Sendmail – Fasterland
Checking if PHP/WordPress can send mails
取用php交互模式去测试看看
结果:
[root@xxx ~]# php -a
Interactive mode enabled

mail ('
crifan.li@xxx
', "Test php send mail title", "Test php send mail title", "From:
 
[email protected]
");
exit();
^C
没反应啊。
[root@xxx ~]# cat testphpmail.php
<?php
        mail ('
crifan.li@xxx
', "Test php send mail title", "Test php send mail title", "From:
 
[email protected]
");
?>
[root@xxx ~]# php -f testphpmail.php
[root@xxx ~]#
好像没有任何错误。
和之前一样,log中发送也是OK的也是没有错误:
Mar 27 13:17:29 xxx sendmail[2770]: w2R5HTp5002770: from=root, size=157, class=0, nrcpts=1, msgid=<
201803270517.w2R5HTp5002770@xxx
>, relay=root@localhost
Mar 27 13:17:30 xxx sendmail[2771]: w2R5HTKM002771: <
crifan.li@xxx
>... User unknown
Mar 27 13:17:30 xxx sendmail[2770]: w2R5HTp5002770: to=
crifan.li@xxx
, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30157, relay=[127.0.0.1] [127.0.0.1], dsn=5.1.1, stat=User unknown
Mar 27 13:17:30 xxx sendmail[2771]: w2R5HTKM002771: from=<
root@xxx
>, size=157, class=0, nrcpts=0, proto=ESMTP, daemon=MTA, relay=localhost [127.0.0.1]
Mar 27 13:17:30 xxx sendmail[2770]: w2R5HTp5002770: w2R5HTp6002770: DSN: User unknown
Mar 27 13:17:30 xxx sendmail[2771]: w2R5HTKO002771: from=<>, size=2044, class=0, nrcpts=1, msgid=<
201803270517.w2R5HTp6002770@xxx
>, proto=ESMTP, daemon=MTA, relay=localhost [127.0.0.1]
Mar 27 13:17:30 xxx sendmail[2770]: w2R5HTp6002770: to=root, delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=31181, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (w2R5HTKO002771 Message accepted for delivery)
Mar 27 13:17:30 xxx sendmail[2772]: w2R5HTKO002771: to=<
root@xxx
>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=32226, dsn=2.0.0, stat=Sent
所以应该就是端口问题了。
只能继续等待端口通过了。

转载请注明:在路上 » 【未解决】继续调试主页中php发送邮件的功能

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.185 seconds, using 22.15MB memory