title: Connect to Gmail with PHP & IMAP
body: <p>I have enabled <code>OpenSSL</code> and <code>IMAP</code> functions from my <code>php.ini</code> file and <code>phpinfo()</code> confirms it.</p>
  
  <p>By using the code below i can connect to a Hotmail account but not to a Gmail account.(of course i change the <code>$connect_to</code> to point to Hotmail.)</p>
  
  <pre><code>$connect_to = '{imap.gmail.com:993/imap/ssl}INBOX';
  $connection = imap_open($connect_to, $user, $password)
    or die("Can't connect to '$connect_to': " . imap_last_error());
  imap_close($connection);
  </code></pre>
  
  <p>The returned error is </p>
  
  <pre><code>Warning: imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX in /opt/lampp/htdocs/webmail_client_practise/index.php on line 6
  Can't connect to '{imap.gmail.com:993/imap/ssl}INBOX': Certificate failure for imap.gmail.com: unable to get local issuer certificate: /C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
  Notice: Unknown: Certificate failure for imap.gmail.com: unable to get local issuer certificate: /C=US/O=GeoTrust Inc./CN=GeoTrust Global CA (errflg=2) in Unknown on line 0
  </code></pre>
  
  <p>Unfortunately i cannot find a complete tutorial of how to use the IMAP functions.</p>
  
  <p>Any ideas, solutions or suggestions will be helpful.</p>