PHP - IMAP connection to Gmail returns nothing - php

I am trying to connect to gmail using IMAP. When I try to load the script, the page just loads and and doesn't return anything. No error, no emails... it just tries loading.
I have IMAP enabled for PHP, and it's also enabled in my Gmail inbox.
$hostname = '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX';
$username = 'email#gmail.com';
$password = 'password';
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
imap_close($inbox);
Any ideas why the script won't stop loading?

Firewall was blocking the port 993. Got it working. Thanks!

Related

How do I resolve IMAP connectivity error?

Can anybody help regarding this issue. The email didn't received through the imap_open function. I have seen a problem with this function.
imap_open($hostname, $username, $password) or die('Cannot connect to Server: ' . imap_last_error());
First url with port
$hostname = '{imap-mail.outlook.com:143/imap}INBOX';
Second URL with port
$hostname = '{imap-mail.outlook.com:993/imap/ssl/novalidate-cert}INBOX';
I want to resolve this problem using imap_open function.

Getting error while fetching emails via imap

i have problem in IMAP
i am writing below code to fetch inbox emails
$hostname = '{mail.test.in:110}INBOX';
$username='name';
$password='password';
$inbox = imap_open($hostname, $username, $password) or die('Cannot connect to Gmail: ' . imap_last_error());
i am getting error
"message": "imap_open(): Couldn't open stream {mail.innovify.in:110}INBOX"
please let me know solution
According to the imap_open() documentation you need to provide a service flag if you are not using IMAP.
You are using port 110 which is for POP3, so you need to let imap_open() know about that by changing your connection string from
$hostname = '{mail.test.in:110}INBOX';
to
$hostname = '{mail.test.in:110/pop3}INBOX';

Unable to connect to Gmail, using php imap

I'm trying to use imap with php to retrieve mails from gmail using the following code:
<?php
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'myaccount#gmail.com';
$password = 'mypassword';
$inbox = imap_open($hostname,$username,$password)
or die('Cannot connect to Gmail: ' . imap_last_error());
?>
However, imap_last_error throws me the following error:
"Unable to create TCP socket: Address family not supported by protocol"
I have imap enabled on my gmail account. imap 2007e with ssl (and OpenSSL) and kerberos seems to be enabled on the webserver. I don't have control on the domains ports, but support told me "Outgoing IMAP connections can be made, this is not blocked.".
I see I'm not the only one having trouble connecting to gmail using IMAP. However, I didn't find anyone who encountered this error.

PHP Getting imap open to work

I just moved my app to the cloud hosting. I was using imap_open to access mails in my gmail account. It worked fine.
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = '...#gmail.com';
$password = '****';
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
Now I get an error Unable to create selectable TCP socket (1176 >= 1024) Does anybody have any idea about this error. I appreciate any help.
Thanks.
It looks to me like you've hit the maximum amount of open file descriptors. Maybe restarting your system?

PHP imap gmail not connecting [Edited!!]x2

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
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.
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.

Categories