PHP imap_open(): invalid remote specification when trying connect to GMAIL
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 specifica开发者_JAVA技巧tion
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!
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
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.
$iconnect = imap_open("{imap.gmail.com:993/ssl/novalidate-cert}INBOX","user@gmail.com","passwordofuser") or die(imap_errors());
Check this code this will connect to gmail server .
精彩评论