无法从我的本地计算机发送电子邮件到谷歌

osh*_*nen 2 php linux email postfix-mta

以下为什么不工作?

<?php

    mail('oshirowanen@gmail.com', 'some text here', 'some text here');

?>
Run Code Online (Sandbox Code Playgroud)

access.log显示:

127.0.0.1 - - [16/Jan/2013:08:46:52 +0000] "GET /test_mail.php HTTP/1.1" 200 294 "-" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/536.11 (KHTML, like Gecko) Ubuntu/12.04 Chromium/20.0.1132.47 Chrome/20.0.1132.47 Safari/536.11"

error.log显示:

nothing

我也从终端尝试了以下内容:

echo 'body' | sendmail recipient@example.net
Run Code Online (Sandbox Code Playgroud)

没别的了.

和mail.log显示:

Jan 16 08:57:24 ubuntu postfix/smtp[4081]: connect to alt1.gmail-smtp-in.l.google.com[2a00:1450:4001:c02::1a]:25: Network is unreachable
Run Code Online (Sandbox Code Playgroud)

我的收件箱或垃圾邮件箱中没有收到电子邮件.

Cha*_*les 7

postfix/smtp[4081]: connect to alt1.gmail-smtp-in.l.google.com[2a00:1450:4001:c02::1a]:25: Network is unreachable

看起来您正在使用启用IPv6支持的 Postfix ,但您不在连接到Internet的IPv6网络上,或者具有阻止连接的防火墙规则.

最简单的故障排除方法是编辑main.cf和更改inet_protocols,ipv4而不是当前设置的任何内容.进行此更改后,请务必完全重新启动Postfix服务.链接的文档页面将提供有关启用IPv6支持的含义的更多信息.

如果在下载到IPv4后仍无法连接,请在系统和Internet之间查找防火墙规则.

我还是要积极地鼓励你使用PHP的mail()功能. mail()不能保证交货.所有这一切都保证了它试图将邮件传递给幕后的东西.当出现问题时,它不会给你任何线索.相反,请将第三方邮件库(如SwiftmailerPHPMailer)与已知工作的SMTP服务器结合使用.这些库使得在发送时出现问题时更加明显,并且您获得了非常有用的启动功能.