Search code examples
phpemailgmailpop3

Extracting Content from Email


I want to develop an application that would extract the following things from an email id,

  • A notification about a new email
  • Subject
  • Sender
  • Total Unread emails

Now as I think it wont be easy to extract emails from all of the major email providers so I basically want to do it for Gmail.

I just need to find the way to do it. Please guide me. Thanks


Solution

  • It's actually fairly easy using the PHP IMAP extension. There are lots of functions there that you can use to list all emails in an inbox, get a count of them. Read their subjects or contents and such.

    In GMail labels are the equivalent of folders in the IMAP docs.

    You can connect to a GMail like this:

    $mailbox = imap_open('{imap.gmail.com:993/imap/ssl}', '[email protected]', $password);
    

    Oh! Also you need to log in to GMail on the account you won't to allow email access to, go to Mail Settings -> Forwarding and POP/IMAP-> Enable IMAP