Tutorials, PHP & MySQL, IMAP

Connecting to Gmail with imap_open

Using PHP connecting to an POP/IMAP server is a relatively easy process, it can be useful for using webmail or to allow a script to download all emails and store in a database for instance.

The function required to make the connection is imap_open, it expects three parameters first the connection string made up of the remote host and mailbox folder, followed by the username and password.

a typical example:

imap_open("{imap.gmail.com:993/ssl/novalidate-cert}INBOX","user@gmail.com","passwordofuser") or die(imap_errors()); 

The above should work just fine, I've found a large number of blogs/articles using that path. 
I've not had any success with that, Google may have updated this recently, tested the above locally and on a remote server.

In order to make the connection remove the novalidate-cert.

imap_open("{imap.gmail.com:993/ssl}INBOX","user@gmail.com","passwordofuser") or die(imap_errors()); 

 

David Carr

David Carr

For the past 12 years, I’ve been developing applications for the web using mostly PHP. I do this for a living and love what I do as every day there is something new and exciting to learn.

In my spare time, the web development community is a big part of my life. Whether managing online programming groups and blogs or attending a conference, I find keeping involved helps me stay up to date. This is also my chance to give back to the community that helped me get started, a place I am proud to be apart of.

Besides programming I love spending time with friends and family and can often be found together going out catching the latest movie, staying in playing games on the sofa or planning a trip to someplace I’ve never been before.