Connecting to Gmail IMAP PHP "Couldn't open stream"

cream picture cream · Aug 2, 2012 · Viewed 27.4k times · Source

There are lots of people having similar issues but no one is answering their questions. I have IMAP enabled in PHP, Using all the correct information. I don't see where I'm going wrong.

Here's my code:

$hostname = '{imap.gmail.com:995/imap/ssl/novalidate-cert}'; 
$username = '[email protected]'; $password = 'password'; 
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());

print_r(imap_errors());

Not returning any errors other than:

Warning: imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com:995/imap/ssl/novalidate-cert} in /home/a8066360/public_html/test/imap.php on line 6

Cannot connect to Gmail: Can't connect to gmail-imap.l.google.com, 995: Connection timed out

I've noticed that if I change the single quotes to `

shell_exec() has been disabled for security reasons...

Please help!!!

Answer

Max picture Max · Aug 2, 2012

You need port 993, the SSL IMAP port.

Port 995 is the SSL POP3 port.