php imap_open : 无法打开到我的邮件服务器的流

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22787369/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:15:54  来源:igfitidea点击:

imap_open : couldn't open stream to my mail server

phpemailimap

提问by TOZ

Notice: Unknown: Connection failed to mail.domain.com,143: Connection timed out (errflg=2) in Unknown on line 0

注意:未知:连接到 mail.domain.com 失败,143:连接超时(errflg=2)在第 0 行的未知中

imap_open("{mail.domain.com:143/novalidate-cert}INBOX", 'login', 'password')

The port 143 is open, I'm not behind a firewall, my server uses self-signed certificates.

端口 143 已打开,我不在防火墙后面,我的服务器使用自签名证书。

I really don't understand why I can not connect to my mail server

我真的不明白为什么我无法连接到我的邮件服务器

I searched everywhere but I found no answer..

我到处搜索,但没有找到答案..

采纳答案by TOZ

Thank you for your answers. My mistake was not coming from the connection but rather a loop that crashed the server when I had too much email :

谢谢您的回答。我的错误不是来自连接,而是当我有太多电子邮件时导致服务器崩溃的循环:

imap_open("{mail.domain.com:143/novalidate-cert}INBOX", 'login', 'password')

$mails = imap_search($stream, 'UNSEEN');

rsort($mails);
foreach ($mails as $mailId) {
  imap_fetch_overview($stream, $mailId, 0);
} //that was the mistake when email number is too big!

回答by Carl

In my case, this did the trick:

就我而言,这解决了问题:

imap_open("{mail.domain.com:110/pop3/notls}INBOX", 'login', 'password')

回答by Adam Fischer

My guess is that you are behind ssl (default port 993)

我的猜测是你在 ssl 后面(默认端口 993)

Try

尝试

imap_open("{mail.domain.com:993/imap/ssl/novalidate-cert}INBOX", 'login', 'password') or die('Cannot connect: ' . print_r(imap_errors(), true))

Dont forget to open that port

不要忘记打开那个端口

回答by Vivek Muthal

I have written a library.
Don't know it will work for your host or not.
But you could surely try it. http://vivoauthimap.vivsoftware.in/

我写了一个库。
不知道它是否适用于您的主机。
但你肯定可以试试。http://vivoauthimap.vivsoftware.in/

回答by MakG

In my case, the imap extension was compiled without the --with-imap-ssloption. You need to pass it to configureor if you're using Docker:

就我而言,imap 扩展是在没有--with-imap-ssl选项的情况下编译的。您需要将它传递给configure或者如果您正在使用 Docker:

docker-php-ext-configure imap --with-imap-ssl
docker-php-ext-install imap

You can verify if there is an SSL Support using this command:

您可以使用以下命令验证是否有 SSL 支持:

php -i | grep imap -A 5

If there is no "SSL Support => enabled" string, you need to recompile the imap extension.

如果没有“SSL Support => enabled”字符串,则需要重新编译 imap 扩展。

Lack of SSL Support was resulting in not very clear error messages:

缺乏 SSL 支持导致错误消息不是很清楚:

Warning: imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX
Can't open mailbox {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX: invalid remote specification