从 php 发送电子邮件时出现问题

从 php 发送电子邮件时出现问题

我正在尝试设置一个服务器,以便我可以使用 mail() 函数从 PHP 发送电子邮件。我尝试运行一个我知道有效的脚本,但从未收到电子邮件。这是日志文件:

Sep  1 13:58:27 server1 postfix/master[5318]: daemon started -- version 2.5.5, configuration /etc/postfix
Sep  1 13:59:21 server1 dovecot: Dovecot v1.0.15 starting up
Sep  1 13:59:21 server1 dovecot: Generating Diffie-Hellman parameters for the first time. This may take a while..
Sep  1 13:59:22 server1 dovecot: Killed with signal 15
Sep  1 13:59:22 server1 dovecot: Dovecot v1.0.15 starting up
Sep  1 13:59:22 server1 dovecot: Generating Diffie-Hellman parameters for the first time. This may take a while..
Sep  1 13:59:22 server1 dovecot: Killed with signal 15
Sep  1 13:59:22 server1 dovecot: Dovecot v1.0.15 starting up
Sep  1 13:59:22 server1 dovecot: Generating Diffie-Hellman parameters for the first time. This may take a while..
Sep  1 14:12:37 server1 postfix/master[5318]: terminating on signal 15
Sep  1 14:12:37 server1 postfix/master[5998]: daemon started -- version 2.5.5, configuration /etc/postfix
Sep  1 14:12:41 server1 dovecot: Killed with signal 15
Sep  1 14:12:41 server1 dovecot: Dovecot v1.0.15 starting up
Sep  1 14:21:16 server1 postfix/master[5998]: terminating on signal 15
Sep  1 14:21:18 server1 dovecot: Killed with signal 15
Sep  1 14:22:14 server1 postfix/master[2031]: daemon started -- version 2.5.5, configuration /etc/postfix
Sep  1 14:24:31 server1 postfix/master[2033]: daemon started -- version 2.5.5, configuration /etc/postfix
Sep  1 14:25:22 server1 dovecot: Dovecot v1.0.15 starting up
Sep  1 14:39:44 server1 postfix/master[2033]: terminating on signal 15
Sep  1 14:39:48 server1 dovecot: Killed with signal 15
Sep  1 14:40:43 server1 postfix/master[2033]: daemon started -- version 2.5.5, configuration /etc/postfix
Sep  1 14:40:44 server1 dovecot: Dovecot v1.0.15 starting up
Sep  1 14:43:28 server1 postfix/pickup[2042]: 5FAEE256327: uid=33 from=<www-data>
Sep  1 14:43:28 server1 postfix/cleanup[2214]: 5FAEE256327: message-id=<[email protected]>
Sep  1 14:43:28 server1 postfix/qmgr[2044]: 5FAEE256327: from=<[email protected]>, size=418, nrcpt=1 (queue active)
Sep  1 14:43:28 server1 postfix/smtp[2216]: connect to gmail-smtp-in.l.google.com[209.85.210.23]:25: No route to host
Sep  1 14:43:28 server1 postfix/smtp[2216]: connect to alt1.gmail-smtp-in.l.google.com[209.85.212.8]:25: No route to host
Sep  1 14:43:28 server1 postfix/smtp[2216]: connect to alt2.gmail-smtp-in.l.google.com[209.85.219.43]:25: No route to host
Sep  1 14:43:28 server1 postfix/smtp[2216]: connect to alt3.gmail-smtp-in.l.google.com[209.85.129.114]:25: No route to host
Sep  1 14:43:28 server1 postfix/smtp[2216]: connect to alt4.gmail-smtp-in.l.google.com[209.85.222.4]:25: No route to host
Sep  1 14:43:28 server1 postfix/smtp[2216]: 5FAEE256327: to=<[email protected]>, relay=none, delay=0.26, delays=0.11/0.04/0.11/0, dsn=4.4.1, status=deferred (connect to alt4.gmail-smtp-in.l.google.com[209.85.222.4]:25: No route to host)

我猜这与“没有通往主机的路线”有关......有什么想法吗?

答案1

您需要先解决“无路由到主机”问题,然后才能收发电子邮件。您可以通过从服务器运行以下命令来测试它:

   telnet 209.85.222.4 25

它看起来应该是这样的:

   guin:~$ telnet 209.85.222.4 25
   Trying 209.85.222.4...
   Connected to 209.85.222.4.
   Escape character is '^]'.
   220 mx.google.com ESMTP 4si19030170pzk.29
   quit
   221 2.0.0 closing connection 4si19030170pzk.29
   Connection closed by foreign host.
   zsh: exit 1     telnet 209.85.222.4 25
   guin:~$ 

我输入“quit”退出。如果您没有看到“220”行,则说明您的服务器在连接远程邮件服务器时出现问题。

如果是这种情况,我猜测这要么是路由问题(缺少默认路由?检查“netstat -nr”输出),要么是防火墙问题(检查“iptables-save | less”输出)。

肖恩

答案2

仅供参考:Google Mail 今天早些时候出现故障。您没有说明这是否给其他主机带来了麻烦。

如果这仍然给您带来麻烦,那么您的网络管理员可能正在阻止传出端口 25。一些 ISP 这样做是为了阻止垃圾邮件。您可以联系您的网络管理员了解详细信息。

答案3

这些 IP 可以从你的服务器访问;我猜你没有连接到它们,尽管你的 DNS 解析了 Gmail 的 MX

尝试通过 25 端口 telnet 到至少一个 ip 地址

请检查您的路由和防火墙规则

答案4

在您的服务器上,您可以尝试这个命令:sendmail[电子邮件保护] 主题:测试 CTRL +D

然后 cat /var/log/mail.info 并检查邮件是否已发送。如果您在从终端发送电子邮件时遇到任何问题,则 php 无法正常工作。

告诉我们命令给了你什么

相关内容