title: How to get Gmail unread count
body: <p>I am using the following code to get the Unread emails count in Gmail. However, it is returning the error: </p>
  
  <pre><code>can't connect: Too many login failures
  </code></pre>
  
  <p>Is there anything I am missing here?</p>
  
  <p>(IMAP and POP are enabled in the Gmail account I am testing.)</p>
  
  <hr>
  
  <p><em><strong>NOTE:</strong> It looks like it is working (at least for most of the requests). However, it is taking way too long - maybe 2 - 3 minutes to come back with a number. Is there a way to speed it up?</em></p>
  
  <hr>
  
  <p>Thanks!</p>
  
  <pre><code>&lt;?php
  
  $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); 
  if ($check) { 
  print $check-&gt;Unread; //. "/" . $check-&gt;Nmsgs; 
  } else { 
  print "Failed"; 
  }
  
  ?&gt;
  </code></pre>