无法向我自己的域发送电子邮件

时间:2014-10-24 16:45:26

标签: php email ubuntu sendmail

我在我的ubuntu服务器上设置了sendmail,并设置了以下PHP代码,以通过电子邮件发送我自己的域contact@example.com

$subject = "Hello!";
$message = "This is a test.";

$header = "From: " . $email . "\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

mail("contact@example.com", $subject, $message, $header);

然而,电子邮件永远不会到来。但是,当我将目标电子邮件更改为Gmail或Yahoo时,电子邮件发送就好了。

这是我的mail.log文件的输出:

Oct 24 16:41:17 CA2EXAMPLE01 sendmail[4476]: s9OGfHVe004476: from=www-data, size=186, class=0, nrcpts=1, msgid=<201410241641.s9OGfHVe004476@CA2EXAMPLE01.example.com>, relay=www-data@localhost
Oct 24 16:41:17 CA2EXAMPLE01 sm-mta[4477]: s9OGfHeD004477: from=<www-data@CA2EXAMPLE01.example.com>, size=431, class=0, nrcpts=1, msgid=<201410241641.s9OGfHVe004476@CA2EXAMPLE01.example.com>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Oct 24 16:41:17 CA2EXAMPLE01 sendmail[4476]: s9OGfHVe004476: to=contact@example.com, ctladdr=www-data (33/33), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30186, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (s9OGfHeD004477 Message accepted for delivery)
Oct 24 16:41:17 CA2EXAMPLE01 sm-mta[4479]: s9OGfHeD004477: to=<contact@example.com>, ctladdr=<www-data@CA2EXAMPLE01.example.com> (33/33), delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=120431, relay=mail.example.com. [11.23.41.55], dsn=4.0.0, stat=Deferred: Connection refused by mail.example.com.

我在错误日志中看到的主要问题是Deferred: Connection refused by mail.example.com,但我不确定是什么问题。

2 个答案:

答案 0 :(得分:1)

您需要更改后缀的配置

vim /etc/postfix/main.cf

并从mydestination的值

中删除您的域名

答案 1 :(得分:0)

您需要为loopback ip添加一个条目:

#add this to bind hostname
127.0.0.1      CA2EXAMPLE01.example.com//whatever you meant by mail.example.com