简体   繁体   English

PHP imap仅适用于IP地址,不适用于域名-DNS问题?

[英]PHP imap only works with IP address, not with domain name - DNS issue?

I'm displaying a simple list of emails using the imap_* functions of PHP: 我正在使用PHP的imap_*功能显示电子邮件的简单列表:

$connection = "{mail-server:993/ssl/novalidate-cert}INBOX";
$imap = imap_open($connection, 'my-login', 'my-pass');
$check = imap_check($imap);
$overview = imap_fetch_overview($imap, "1:{$check->Nmsgs}", 0);
foreach ($overview as $msg) {
    echo "{$msg->msgno} ({$msg->date}), from {$msg->from}: {$msg->subject}\n";
}
imap_close($imap);

I'm connecting to the same machine. 我正在连接到同一台机器。 This works perfectly fine and I see the list of emails. 这工作得很好,我看到了电子邮件列表。 However, at the very bottom of the page, a notice is shown: 但是,在页面的最底部,将显示一个通知:

Notice: Unknown: Can't connect to mail-server,993: Connection refused (errflg=1) in Unknown on line 0 注意:未知:无法连接到邮件服务器,993:在第0行的未知中,连接被拒绝(errflg = 1)

This notice is shown when I use my domain name or localhost(!) as mail-server. 当我将域名或localhost(!)用作邮件服务器时,将显示此通知。 When I use my IP address or 127.0.0.1, everything works fine. 当我使用IP地址或127.0.0.1时,一切正常。 I got that idea from this question . 我从这个问题中得到了这个主意。


I did an nslookup for both my domain name and localhost, from the machine itself. 我从机器本身为域名和本地主机做了nslookup。 Both return the right IP address, however, both also show that it is a 'Non-authoritative answer'. 两者都返回正确的IP地址,但是,两者也都表明它是“非权威性答案”。

Here's the contents of /etc/hosts : 这是/etc/hosts的内容:

127.0.0.1   localhost
# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

I don't understand how nslookup localhost can give 127.0.0.1 as a non-authoritative answer if it's in the hosts file. 我不明白nslookup localhost如何在主机文件中提供127.0.0.1作为非权威性答案。


Anyway, am I right that PHP throwing this notice is because of the DNS being non-authoritative? 无论如何,PHP发出此通知是因为DNS不具有权威性,对吗? If so, how can I fix it? 如果是这样,我该如何解决? If not, how can I fix it? 如果没有,我该如何解决?

I don't experience any other issues with the DNS. DNS没有其他问题。 I can access the machine from everywhere using its domain name. 我可以使用其域名从任何地方访问该计算机。 Also note that PHP actually can connect when I use the domain name - it just also spits out the notice. 另请注意,当我使用域名时,PHP实际上可以连接-它也发出通知。

Also, there's no problem using thunderbird on a remote computer using the same connection. 同样,在具有相同连接的远程计算机上使用雷鸟也没有问题。

I'm running Ubuntu 14.04, PHP 5.5.9, and Dovecot 2.2.9 for the IMAP server. 我正在为IMAP服务器运行Ubuntu 14.04,PHP 5.5.9和Dovecot 2.2.9。

This can happen when your lookup resolves to an IPv6 address, but your server isn't configured to support IPv6. 当您的查询解析为IPv6地址,但您的服务器未配置为支持IPv6时,可能会发生这种情况。 The client will first try the IPv6 address, and then the IPv4 address when that fails. 客户端将首先尝试IPv6地址,然后在失败时尝试IPv4地址。

You can check if this is the case by removing localhost from the line: 您可以通过从行中删除localhost来检查是否是这种情况:

::1     localhost ip6-localhost ip6-loopback

in your hosts file. 在您的hosts文件中。

Authoritative/non-authoritative DNS queries don't make a difference here. 权威/非权威DNS查询在这里没有任何区别。 See https://serverfault.com/q/413124/265582 for more information. 有关更多信息,请参见https://serverfault.com/q/413124/265582

You can also let dovecot accept ipv6 connections. 您也可以让dovecot接受ipv6连接。 How to do that depends on your configuration. 如何执行取决于您的配置。 If you have inet_listener blocks, make sure that the address line contains :: . 如果您有inet_listener块,请确保address行包含:: For example: 例如:

inet_listener {
  address = *, ::
  port = 143
}
inet_listener {
  address = *, ::
  port = 993
  ssl = yes
}

If you don't have inet_listener blocks, change the listen directive to: 如果没有inet_listener块,请将listen指令更改为:

listen=[::]

In both cases, this will make dovecot listen on both ipv4 and ipv6 connections. 在这两种情况下,这都会使dovecot在ipv4和ipv6连接上进行侦听。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM