AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 571210
Accepted
OtagoHarbour
OtagoHarbour
Asked: 2020-03-05 17:57:56 +0800 CST2020-03-05 17:57:56 +0800 CST 2020-03-05 17:57:56 +0800 CST

从 PHP 脚本发送的邮件未显示

  • 772

我在两个运行 Ubuntu 的 AWS EC2 实例上运行一个网站。我正在使用灯。以下 PHP 代码用于成功发送电子邮件,以警告可疑活动,但在 2020 年 1 月停止这样做。

<?php
    // Function to email notification of suspicious entry
    function emailPossibleSQLInjectionNotification($ipAddress, $emailAddress, $field, $entry, $time)
    {
            $to = "[email protected]";
            $subject = "Suspicious activity";
            $message = "Dear Sir,\n\n" .
                    "The following invalid entry was entered for " . $field . ".\n\n" .
                    $field . ": " .  $entry . "\n" .
                    "Client IP address" . ": " .  $ipAddress . "\n" .
                    "Client email address" . ": " .  $emailAddress . "\n" .
                    "Time" . ": " .  $time . "\n\n" .
                    "Have a wonderful day!\nWeb Site Name.\n";
            $from = "[email protected]";
            $headers = "From:" . $from;
            mail($to,$subject,$message,$headers);
    }
?>

以下

cat /var/log/mail.log

返回

Mar  5 00:30:41 ip-10-0-1-76 sm-mta[30561]: 02339OqL008906: to=<[email protected]>, ctladdr=<[email protected]> (33/33), delay=1+21:21:17, xdelay=00:00:00, mailer=esmtp, pri=19290583, relay=alt4.gmail-smtp-in.l.google.com., dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
Mar  5 00:39:01 ip-10-0-1-76 sendmail[30620]: 0250d12h030620: from=root, size=550, class=0, nrcpts=1, msgid=<[email protected]>, bodytype=8BITMIME, relay=root@localhost
Mar  5 00:39:01 ip-10-0-1-76 sm-mta[30621]: 0250d14c030621: from=<[email protected]>, size=848, class=0, nrcpts=1, msgid=<[email protected]>, bodytype=7BIT, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Mar  5 00:39:01 ip-10-0-1-76 sendmail[30620]: 0250d12h030620: to=root, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30550, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (0250d14c030621 Message accepted for delivery)
Mar  5 00:39:01 ip-10-0-1-76 sm-mta[30622]: 0250d14c030621: to=<[email protected]>, ctladdr=<[email protected]> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=local, pri=31084, dsn=2.0.0, stat=Sent
 Mar  5 00:40:41 ip-10-0-1-76 sm-mta[30576]: 023MRjPq024050: to=<[email protected]>, ctladdr=<[email protected]> (33/33), delay=1+02:12:56, xdelay=00:10:36, mailer=esmtp, pri=7140592, relay=alt4.gmail-smtp-in.l.google.com. [172.217.218.26], dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
Mar  5 00:40:41 ip-10-0-1-76 sm-mta[30576]: 023H1exj022946: to=<[email protected]>, ctladdr=<[email protected]> (33/33), delay=1+07:39:01, xdelay=00:00:00, mailer=esmtp, pri=9660592, relay=alt4.gmail-smtp-in.l.google.com., dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
Mar  5 00:40:41 ip-10-0-1-76 sm-mta[30576]: 02339OqL008906: to=<[email protected]>, ctladdr=<[email protected]> (33/33), delay=1+21:31:17, xdelay=00:00:00, mailer=esmtp, pri=19380583, relay=alt4.gmail-smtp-in.l.google.com., dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
Mar  5 00:50:41 ip-10-0-1-76 sm-mta[30646]: 024KKwfi029723: to=<[email protected]>, ctladdr=<[email protected]> (33/33), delay=04:29:43, xdelay=00:10:36, mailer=esmtp, pri=1290584, relay=alt4.gmail-smtp-in.l.google.com. [172.217.218.26], dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
Mar  5 00:50:41 ip-10-0-1-76 sm-mta[30646]: 023H1exj022946: to=<[email protected]>, ctladdr=<[email protected]> (33/33), delay=1+07:49:01, xdelay=00:00:00, mailer=esmtp, pri=9750592, relay=alt4.gmail-smtp-in.l.google.com., dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
Mar  5 00:50:41 ip-10-0-1-76 sm-mta[30646]: 02339OqL008906: to=<[email protected]>, ctladdr=<[email protected]> (33/33), delay=1+21:41:17, xdelay=00:00:00, mailer=esmtp, pri=19470583, relay=alt4.gmail-smtp-in.l.google.com., dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
Mar  5 01:00:41 ip-10-0-1-76 sm-mta[30660]: 023MRjPq024050: to=<[email protected]>, ctladdr=<[email protected]> (33/33), delay=1+02:32:56, xdelay=00:10:36, mailer=esmtp, pri=7230592, relay=alt4.gmail-smtp-in.l.google.com. [172.217.218.26], dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
Mar  5 01:00:41 ip-10-0-1-76 sm-mta[30660]: 023H1exj022946: to=<[email protected]>, ctladdr=<[email protected]> (33/33), delay=1+07:59:01, xdelay=00:00:00, mailer=esmtp, pri=9840592, relay=alt4.gmail-smtp-in.l.google.com., dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
Mar  5 01:00:41 ip-10-0-1-76 sm-mta[30660]: 02339OqL008906: to=<[email protected]>, ctladdr=<[email protected]> (33/33), delay=1+21:51:17, xdelay=00:00:00, mailer=esmtp, pri=19560583, relay=alt4.gmail-smtp-in.l.google.com., dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
Mar  5 01:07:30 ip-10-0-1-76 sendmail[30700]: 02517Uj6030700: from=www-data, size=342, class=0, nrcpts=1, msgid=<[email protected]>, relay=www-data@localhost
Mar  5 01:07:30 ip-10-0-1-76 sm-mta[30701]: 02517UA4030701: from=<[email protected]>, size=583, class=0, nrcpts=1, msgid=<[email protected]>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Mar  5 01:07:30 ip-10-0-1-76 sendmail[30700]: 02517Uj6030700: [email protected], ctladdr=www-data (33/33), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30342, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (02517UA4030701 Message accepted for delivery)
Mar  5 01:09:01 ip-10-0-1-76 sendmail[30846]: 025191nX030846: from=root, size=550, class=0, nrcpts=1, msgid=<[email protected]>, bodytype=8BITMIME, relay=root@localhost
Mar  5 01:09:01 ip-10-0-1-76 sm-mta[30847]: 025191Bc030847: from=<[email protected]>, size=848, class=0, nrcpts=1, msgid=<[email protected]>, bodytype=7BIT, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Mar  5 01:09:01 ip-10-0-1-76 sendmail[30846]: 025191nX030846: to=root, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30550, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (025191Bc030847 Message accepted for delivery)
Mar  5 01:09:01 ip-10-0-1-76 sm-mta[30848]: 025191Bc030847: to=<[email protected]>, ctladdr=<[email protected]> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=local, pri=31084, dsn=2.0.0, stat=Sent

以下

$ sudo netstat -ntlp | grep sendmail

返回

tcp        0      0 127.0.0.1:587           0.0.0.0:*               LISTEN      
1337/sendmail: MTA:
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      
 1337/sendmail: MTA:

ISP 不会成为问题,因为我是从云上的 AWS EC2 实例运行应用程序。

我注意到

df -i

返回

Filesystem     Inodes  IUsed  IFree IUse% Mounted on
udev           124432    357 124075    1% /dev
tmpfs          126762    472 126290    1% /run
/dev/xvda1     917504 607710 309794   67% /
tmpfs          126762      1 126761    1% /dev/shm
tmpfs          126762      6 126756    1% /run/lock
tmpfs          126762     16 126746    1% /sys/fs/cgroup
tmpfs          126762      4 126758    1% /run/user/1000

所以这不是 inode 的问题。

 ps -e | grep sendmail

返回

  1337 ?        00:00:08 sendmail-mta
  4109 ?        00:00:00 sendmail-mta
  4320 ?        00:00:00 sendmail-mta

邮件只是没有显示,即使是垃圾邮件文件夹。

编辑:

我也试过

ubuntu@ip-10-0-1-76:~$ sendmail [email protected]
Test
ubuntu@ip-10-0-1-76:~$

我的 gmail 帐户中仍然没有邮件显示。

ubuntu email
  • 1 1 个回答
  • 570 Views

1 个回答

  • Voted
  1. Best Answer
    OtagoHarbour
    2020-03-25T15:01:24+08:002020-03-25T15:01:24+08:00

    这是由于 AWS 所做的更改。我解决了如下问题。

    1. 按照此处所述安装并设置 Postfix 。
    2. 编辑 AWS EC2 实例过滤器以允许端口 587 上的 SMTP。
    3. 编辑 /etc/postfix/main.cf 以包括 relayhost = [email-smtp.us-east-1.amazonaws.com]:587。
    4. sudo 后缀重新加载
    • 0

相关问题

  • 用文件中的点绘制二维图形

  • 如何验证我使用 9.9.9.9 作为 DNS?

  • 并行安装多个 linux 发行版

  • 自编译 OpenVPN 不会从 systemd 启动

  • 接收有关全新 Debian 的电子邮件

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve