title: Connecting to Gmail through IMAP with PHP - SSL context failed
body: <p>I'm trying to connect to Gmail through IMAP with PHP running in Apache.  This is on an Ubuntu 9.04 system.  I've got some sort of PHP configuration issue that is keeping this from working.  First, here's what I did to setup IMAP for PHP:</p>
  
  <pre><code>sudo apt-get install libc-client2007b libc-client2007b-dev
  sudo apt-get install php5-imap
  sudo /etc/init.d/apache2 start
  </code></pre>
  
  <p>When I run phpinfo(), I get the following imap values:</p>
  
  <pre><code>IMAP c-Client Version: 2004
  SSL Support: enabled
  Kerberos Support: enabled
  </code></pre>
  
  <p>Here's my sample code:</p>
  
  <pre><code>&lt;?php
  $connect_to = '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX';
  $user = 'my gmail address';
  $password = 'my gmail password';
  
  $connection = imap_open($connect_to, $user, $password)
    or die("Can't connect to '$connect_to': " . imap_last_error());
  
  imap_close($connection);
  ?&gt;
  </code></pre>
  
  <p>When I execute this code, I get the following output:</p>
  
  <pre><code>Warning: imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX in /var/www/clint/gmail/gmail.php on line 10
  Can't connect to '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX': TLS/SSL failure for imap.gmail.com: SSL context failed
  </code></pre>
  
  <p>Note that I can telnet to imap.gmail.com:993 from this computer.  I can also hookup Evolution (mail reader) to Gmail through IMAP and fetch mail without problems.  So, I don't think this is a firewall issue.  I'm pretty sure I've got something in PHP not setup correctly.</p>
  
  <p>Any ideas?</p>