smarcus3 Posted April 9, 2012 Share Posted April 9, 2012 I cant get this to work and I found a host with imap-ssl here is my code though i've been messing around with it. It cant get the imap_open to work. $mbox = imap_open ("{imap.gmail.com:993/imap/ssl/novalidate-cert/norsh}Inbox", "username", "password", OP_READONLY) or die("can't connect: " . imap_last_error()); $check = imap_mailboxmsginfo($mbox); echo $check->Unread; / Please please help. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/ Share on other sites More sharing options...
trq Posted April 9, 2012 Share Posted April 9, 2012 A better description of your problem would be helpful. Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335582 Share on other sites More sharing options...
smarcus3 Posted April 9, 2012 Author Share Posted April 9, 2012 This is all that it says ... Warning: imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com}INBOX in /home/u332547992/public_html/default.php on line 45 Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335583 Share on other sites More sharing options...
Muddy_Funster Posted April 9, 2012 Share Posted April 9, 2012 how about this? (You will need to change the <[email protected]> to an actual email address without the <> around it) $mbox = imap_open ("{imap.gmail.com:993/imap/ssl/authuser=<[email protected]>}INBOX", "username","password", OP_READONLY) or die ("can't connect: " . imap_last_error()); your /novalidate-cert/norsh switches are for self signed servers, I'm pretty sure google has an authorised certificate or 10 so this isn't needed. Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335585 Share on other sites More sharing options...
smarcus3 Posted April 9, 2012 Author Share Posted April 9, 2012 When I use your code I get this error Warning: imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com:993/imap/ssl/authuser=<[email protected]>}INBOX in /home/u332547992/public_html/default.php on line 45 can't connect: Can't connect to gmail-imap.l.google.com,993: Connection timed out Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335588 Share on other sites More sharing options...
smarcus3 Posted April 9, 2012 Author Share Posted April 9, 2012 Also the page is here if that helps you. http://smarcus3.x11s.org/ Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335589 Share on other sites More sharing options...
Muddy_Funster Posted April 9, 2012 Share Posted April 9, 2012 I used this to connect to my gmail successfully: $mbox = imap_open ("{imap.gmail.com:993/imap/ssl}INBOX", "[email protected]","MyEmailPassword", OP_READONLY) or die ("can't connect: " . imap_last_error()); Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335605 Share on other sites More sharing options...
dcro2 Posted April 9, 2012 Share Posted April 9, 2012 Are you sure your host allows outgoing connections? Try something simple to test it like: echo file_get_contents("http://google.com"); Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335672 Share on other sites More sharing options...
Muddy_Funster Posted April 9, 2012 Share Posted April 9, 2012 Are you sure your host allows outgoing connections? Try something simple to test it like: echo file_get_contents("http://google.com"); having read this http://support.google.com/mail/bin/answer.py?hl=en&answer=78799 and successfully connecting myself as I said in my last post - yeah, we're sure Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335679 Share on other sites More sharing options...
dcro2 Posted April 9, 2012 Share Posted April 9, 2012 Are you sure your host allows outgoing connections? Try something simple to test it like: echo file_get_contents("http://google.com"); having read this http://support.google.com/mail/bin/answer.py?hl=en&answer=78799 and successfully connecting myself as I said in my last post - yeah, we're sure Did you try that from the same host as the OP, http://powrhost.com ? It's a free host and an "unlimited" one at that, so I don't have much faith in them allowing (or maybe not having the capacity to support) outgoing connections to other servers. EDIT: to clarify, the error "Connection timed out" doesn't mean he got the login method wrong or anything. It simply means the PHP script tried to connect to that port but after however many second seconds gave up. I mean connect in the most raw form, just like opening a telnet session to port 993 on imap.gmail.com. If you were to do that, you immediately get: # telnet imap.gmail.com 993 Trying 209.85.225.108... Connected to gmail-imap.l.google.com. Escape character is '^]'. But this PHP script couldn't even get that far, so it seems it's something to do with the host. Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335694 Share on other sites More sharing options...
smarcus3 Posted April 9, 2012 Author Share Posted April 9, 2012 echo file_get_contents("http://google.com"); returned 301 Moved The document has moved here. [/Code] but my connect always times out still. I even tried using a different gmail account with only a few emails in it. Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335720 Share on other sites More sharing options...
dcro2 Posted April 9, 2012 Share Posted April 9, 2012 So not all outgoing connections are blocked, but they probably blocked connections to mail-related ports to prevent spam from being sent using their servers. I just tried it myself using a script I know that works. Sorry, but you'll have to find another host. Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335724 Share on other sites More sharing options...
smarcus3 Posted April 9, 2012 Author Share Posted April 9, 2012 I am now using 000webhosting which after talking to their IT they stated they support IMAP_OPEN but I still get the time out error. I know this has already been talked about on other threads, but do you know of a free host which does allow this. I have tried many now. Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335727 Share on other sites More sharing options...
Andy-H Posted April 9, 2012 Share Posted April 9, 2012 $email = '[email protected]'; $pass = 'yourpassword'; $inbox = imap_open('{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX', $email, $pass, NULL, 1) or die('Cannot connect to Gmail'); Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335731 Share on other sites More sharing options...
dcro2 Posted April 9, 2012 Share Posted April 9, 2012 I'm sure there's some that do allow connection to those ports but I don't personally know any. Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335733 Share on other sites More sharing options...
smarcus3 Posted April 9, 2012 Author Share Posted April 9, 2012 $email = '[email protected]'; $pass = 'yourpassword'; $inbox = imap_open('{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX', $email, $pass, NULL, 1) or die('Cannot connect to Gmail'); That code doesn't work either It still times out. Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335734 Share on other sites More sharing options...
Andy-H Posted April 9, 2012 Share Posted April 9, 2012 What does: var_dump(extension_loaded('openssl')); print? Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335783 Share on other sites More sharing options...
smarcus3 Posted April 9, 2012 Author Share Posted April 9, 2012 What does: var_dump(extension_loaded('openssl')); print? bool(true) Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335786 Share on other sites More sharing options...
smarcus3 Posted April 9, 2012 Author Share Posted April 9, 2012 When I use this code .... $email = 'st********[email protected]'; $pass = '********'; $inbox = imap_open('{imap.gmail.com:993/imap/ssl}INBOX', $email, $pass, NULL, 1) or die('Cannot connect to Gmail'); [/Code] I get this error now [Code]Warning: imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX in /home/a6807236/public_html/default.php on line 56 Cannot connect to Gmail[/Code] Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335788 Share on other sites More sharing options...
dcro2 Posted April 9, 2012 Share Posted April 9, 2012 Andy-H, go make an account at powrhost.com and see for yourself. They have port 993 blocked. I ran this and got a timeout: <?php error_reporting(-1); fsockopen("imap.gmail.com", 993, $errorno, $errstr); echo "$errorno $errstr"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335789 Share on other sites More sharing options...
smarcus3 Posted April 9, 2012 Author Share Posted April 9, 2012 Im using 000WebHost now. Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335790 Share on other sites More sharing options...
Andy-H Posted April 9, 2012 Share Posted April 9, 2012 Have you tried the novalidate-cert flag at 000webhost? Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335794 Share on other sites More sharing options...
smarcus3 Posted April 9, 2012 Author Share Posted April 9, 2012 Yes. I could try using pop port 995? Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335795 Share on other sites More sharing options...
smarcus3 Posted April 9, 2012 Author Share Posted April 9, 2012 My IMAP No longer gives me an error!!!!!!!!! but how do I count unread messages. I switched over to 10x hosting. Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335801 Share on other sites More sharing options...
dcro2 Posted April 9, 2012 Share Posted April 9, 2012 $unread = imap_search($mbox, 'UNSEEN'); $unreadNum = count($unread); Lots of tutorials out there about PHP and IMAP. Quote Link to comment https://forums.phpfreaks.com/topic/260596-unread-messages-gmail/#findComment-1335811 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.