PHP imap_open():尝试连接到 GMAIL 时远程规范无效

发布于 2024-11-24 19:16:26 字数 450 浏览 1 评论 0原文

我尝试从 Gmail 检索邮件并收到以下错误:

Can't open mailbox {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX: invalid remote specification

我的服务器中安装了 OpenSSL 和 IMAP,以下是 openssl 和 IMAP来自 phpinfo() 的 imap 信息;

openssl
OpenSSL support enabled
OpenSSL Library Version OpenSSL 0.9.7l 28 Sep 2006
OpenSSL Header Version

imap

IMAP c-Client Version   2007e
Kerberos Support    enabled

我现在真的很困惑,请帮忙!

I'm trying to retrive mails from Gmail and got following error:

Can't open mailbox {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX: invalid remote specification

OpenSSL and IMAP are installed in my server, following are openssl & imap info from phpinfo();

openssl
OpenSSL support enabled
OpenSSL Library Version OpenSSL 0.9.7l 28 Sep 2006
OpenSSL Header Version

imap

IMAP c-Client Version   2007e
Kerberos Support    enabled

I'm really confused now, please help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

随梦而飞# 2024-12-01 19:16:26

我也遇到过类似的问题。我可以根据个人经验告诉您,虽然您可能安装了 IMAP 和 OpenSSL,但您可能需要重新编译 php install“--with-imap-ssl[=DIR]”。我想做同样的事情并收到同样的错误。我还安装了相同的 OpenSSL 和 IMAP 版本。我已经重新编译了 php,这是我的配置:

./configure --prefix=/usr/local/apache2/php --with-imap=/usr/local/imap-2007f/ --with-curl=/usr/local/curl/ --enable-套接字 --with-imap-ssl=/usr/local/ssl --with-openssl --with-apxs2=/usr/local/apache2/bin/apxs --with-kerberos --没有图标

你当然不需要使用相同的配置,因为它是根据我的需要定制的。

如果您不熟悉编译 php,可以在这里找到源代码:
http://www.php.net/downloads.php
这是关于如何编译 php 和 apache 的基本教程,假设您使用的是 UNIX。它还包括如何使用curl编译它们,您可以使用curl的所有指令并分别用ssl和imap替换它们,它应该可以工作。
http://thermo.sdsu.edu/testhome/phpinstall.html

I have been having a similar issue. I can tell you from personal experience that while you may have IMAP and OpenSSL installed, you may need to recompile php install "--with-imap-ssl[=DIR]." I wanted to do the same thing and received the same error. I also had the same OpenSSL and IMAP versions installed. I have recompiled php, and here is my config:

./configure --prefix=/usr/local/apache2/php --with-imap=/usr/local/imap-2007f/ --with-curl=/usr/local/curl/ --enable-sockets --with-imap-ssl=/usr/local/ssl --with-openssl --with-apxs2=/usr/local/apache2/bin/apxs --with-kerberos --without-iconv

You don't need to use the same config of course, because it is customized for what I need.

In case you are unfamiliar with compiling php, you can find the source here:
http://www.php.net/downloads.php
Here's a basic tutorial on how to compile php and apache, assuming you are on UNIX. It also includes how to compile them with curl, you can use all of the instructions for curl and replace them with ssl and imap respectively and it should work.
http://thermo.sdsu.edu/testhome/phpinstall.html

甜嗑 2024-12-01 19:16:26

对于 Docker,我了解到在调用 docker-php-ext-install 之前 docker-php-ext-configure 时会发生此错误,我就是这样做的误。因此,Dockerfile 中的 RUN 指令必须如下所示:

FROM php:8-fpm-alpine
# ...
RUN apk add imap-dev openssl-dev \
    && docker-php-ext-configure imap --with-imap --with-imap-ssl \
    && docker-php-ext-install imap

而不是

RUN apk add imap-dev openssl-dev \
    && docker-php-ext-install imap \
    && docker-php-ext-configure imap --with-imap --with-imap-ssl

否则,imap 扩展似乎已安装 - 类似 function_exists('imap_open')< 的调用/code> 将返回 true。但所有对 imap_open 的调用
将因上述错误而失败:

无效的远程规范

即使它是已被广泛证明的正确远程规范,例如 {imap.gmail.com:993/imap/ssl/novalidate-cert/norsh}INBOX{imap. gmail.com:993/imap/ssl}INBOX 来自例如 这篇文章。因此,请确保首先配置然后安装扩展。

For Docker I learned that this error occurs when calling docker-php-ext-install before docker-php-ext-configure, which I did by mistake. So the RUN directive in the Dockerfile must look like this:

FROM php:8-fpm-alpine
# ...
RUN apk add imap-dev openssl-dev \
    && docker-php-ext-configure imap --with-imap --with-imap-ssl \
    && docker-php-ext-install imap

instead of

RUN apk add imap-dev openssl-dev \
    && docker-php-ext-install imap \
    && docker-php-ext-configure imap --with-imap --with-imap-ssl

Otherwise, the imap extension seems to be installed - calls like function_exists('imap_open') will return true. But all calls to imap_open
will fail with the mentioned error:

invalid remote specification

Even if it's a correct remote specification which has been widely prooven like {imap.gmail.com:993/imap/ssl/novalidate-cert/norsh}INBOX or {imap.gmail.com:993/imap/ssl}INBOX from e.g. this article. So make sure that you first configure and then install the extension.

挽手叙旧 2024-12-01 19:16:26
 $iconnect = imap_open("{imap.gmail.com:993/ssl/novalidate-cert}INBOX","[email protected]","passwordofuser") or die(imap_errors());

检查此代码,这将连接到 gmail 服务器。

 $iconnect = imap_open("{imap.gmail.com:993/ssl/novalidate-cert}INBOX","[email protected]","passwordofuser") or die(imap_errors());

Check this code this will connect to gmail server .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文