0
votes

I have some php code that I'm trying to use to connect to gmail using imap. Here's the code:

$hostname = '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX';
$tmp_username = 'username';
$tmp_password = 'password';
$inbox = imap_open($hostname, $username, $password) or die(imap_last_error());

And I get this error output everytime i try to connect:

Warning: imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX in /var/www/PHP/EmailScript.php on line 14 Login aborted

I dont understand what could be wrong!! I've heard of people having SSL errors but this doesnt seem to be one of those. Please please please help me!!!!!

Edit: When trying to connect through telnet-ssl to imap.gmail.com i get the following output:

Trying 74.125.155.109... Connected to gmail-imap.l.google.com. Escape character is '^]'.

And nothing else happens, it just sticks there

2
Just to be sure : the $tmp_username and $tmp_password variables are just for the example you posted here : you are using $username and $password in your "real" application ? (I've got the same error you have when I use your code, but if I use $username and $password, the problem disappears) - Pascal MARTIN

2 Answers

0
votes

I was just about to ask if you had a firewall up when you edited your question.

Your router or firewall may be configured to block port 993. You will have to open it to allow communication on that port. If the machine has a system administrator, you'll have to ask them. Otherwise, check the firewall software and/or router.

0
votes

Try the host

{imap.gmail.com:993/imap/ssl} without setting the folder INBOX.

Your code should be:

$hostname = '{imap.gmail.com:993/imap/ssl}';
$tmp_username = 'username';
$tmp_password = 'password';
$inbox = imap_open($hostname, $username, $password) or die(imap_last_error());

If the problem persist check if IMAP function is enabled or disabled in your server.