不能从我的本地机器向谷歌发送电子邮件


Can't send emails from my local machine to google

为什么不工作?

<?php
    mail('oshirowanen@gmail.com', 'some text here', 'some text here');
?>

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

和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

我的收件箱和垃圾邮件箱里没有电子邮件。

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

它看起来像你使用后缀与IPv6支持启用,但你不是在一个IPv6网络连接到互联网,或有防火墙规则阻止连接。

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

如果您在切换到IPv4后仍然无法连接,请查找您的系统和互联网之间的防火墙规则。

我仍然想要积极鼓励你不要使用PHP的mail()函数。mail()保证交付。它只能保证它试图将邮件传递给幕后的某个。当事情出错时,它不会给你任何提示。相反,请将第三方邮件库(如Swiftmailer或PHPMailer)与已知的工作SMTP服务器结合使用。当发送过程中出现问题时,这些库使它变得非常非常明显,并且您可以获得非常有用的特性来引导。

使用以下命令使其工作:

sudo apt-get install sendmail

编辑php.ini取消sendmail的注释-我的位于

/etc/php5/apache2/

sendmail_path = /usr/sbin/sendmail -t -i

保存并重启apache