Ubuntu
從 PHP 腳本發送的郵件未顯示
我在兩個執行 Ubuntu 的 AWS EC2 實例上執行一個網站。我正在使用燈。以下 PHP 程式碼用於成功發送電子郵件,以警告可疑活動,但在 2020 年 1 月停止這樣做。
<?php // Function to email notification of suspicious entry function emailPossibleSQLInjectionNotification($ipAddress, $emailAddress, $field, $entry, $time) { $to = "otagoHarbour@gmail.com"; $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 = "websiteSiteName@websiteSiteName.com"; $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=<otagoHarbour@gmail.com>, ctladdr=<www-data@ip-10-0-1-76.ec2.internal> (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=<202003050039.0250d12h030620@ip-10-0-1-76.ec2.internal>, bodytype=8BITMIME, relay=root@localhost Mar 5 00:39:01 ip-10-0-1-76 sm-mta[30621]: 0250d14c030621: from=<root@ip-10-0-1-76.ec2.internal>, size=848, class=0, nrcpts=1, msgid=<202003050039.0250d12h030620@ip-10-0-1-76.ec2.internal>, 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=<root@ip-10-0-1-76.ec2.internal>, ctladdr=<root@ip-10-0-1-76.ec2.internal> (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=<otagoHarbour@gmail.com>, ctladdr=<www-data@ip-10-0-1-76.ec2.internal> (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=<otagoHarbour@gmail.com>, ctladdr=<www-data@ip-10-0-1-76.ec2.internal> (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=<otagoHarbour@gmail.com>, ctladdr=<www-data@ip-10-0-1-76.ec2.internal> (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=<otagoHarbour@gmail.com>, ctladdr=<www-data@ip-10-0-1-76.ec2.internal> (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=<otagoHarbour@gmail.com>, ctladdr=<www-data@ip-10-0-1-76.ec2.internal> (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=<otagoHarbour@gmail.com>, ctladdr=<www-data@ip-10-0-1-76.ec2.internal> (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=<otagoHarbour@gmail.com>, ctladdr=<www-data@ip-10-0-1-76.ec2.internal> (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=<otagoHarbour@gmail.com>, ctladdr=<www-data@ip-10-0-1-76.ec2.internal> (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=<otagoHarbour@gmail.com>, ctladdr=<www-data@ip-10-0-1-76.ec2.internal> (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=<202003050107.02517Uj6030700@ip-10-0-1-76.ec2.internal>, relay=www-data@localhost Mar 5 01:07:30 ip-10-0-1-76 sm-mta[30701]: 02517UA4030701: from=<www-data@ip-10-0-1-76.ec2.internal>, size=583, class=0, nrcpts=1, msgid=<202003050107.02517Uj6030700@ip-10-0-1-76.ec2.internal>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1] Mar 5 01:07:30 ip-10-0-1-76 sendmail[30700]: 02517Uj6030700: to=otagoHarbour@gmail.com, 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=<202003050109.025191nX030846@ip-10-0-1-76.ec2.internal>, bodytype=8BITMIME, relay=root@localhost Mar 5 01:09:01 ip-10-0-1-76 sm-mta[30847]: 025191Bc030847: from=<root@ip-10-0-1-76.ec2.internal>, size=848, class=0, nrcpts=1, msgid=<202003050109.025191nX030846@ip-10-0-1-76.ec2.internal>, 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=<root@ip-10-0-1-76.ec2.internal>, ctladdr=<root@ip-10-0-1-76.ec2.internal> (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 otagoharbour@gmail.com Test ubuntu@ip-10-0-1-76:~$
我的 gmail 帳戶中仍然沒有郵件顯示。
這是由於 AWS 所做的更改。我解決瞭如下問題。
- 按照此處所述安裝並設置 Postfix 。
- 編輯 AWS EC2 實例過濾器以允許埠 587 上的 SMTP。
- 編輯 /etc/postfix/main.cf 以包含 relayhost =$$ email-smtp.us-east-1.amazonaws.com $$:587.
- sudo 後綴重新載入