PHP Classes
elePHPant
Icontem

Retrieving e-mail messages using PHP from Gmail, Hotmail and Yahoo via POP3 - POP3 e-mail client package blog

Recommend this page to a friend!
  All package blogs All package blogs   POP3 e-mail client POP3 e-mail client   Blog POP3 e-mail client package blog   RSS 1.0 feed RSS 2.0 feed   Blog Retrieving e-mail mes...  
  Post a comment Post a comment   See comments See comments (16)   Trackbacks (0)  

Author: Manuel Lemos

Posted on:

Package: POP3 e-mail client

Nowadays, most Web mail sites provide POP3 support, so you can retrieve your mailbox messages using PHP or any other language.

However, each system uses different ports and encryption configuration that you need to know in order to access them.

This article provides information on the details of accessing the messages on some of the most popular Web mail systems via POP 3.

It also provides a solution to a common problem, which is how to retrieve only the newly received messages when you never delete messages from the mailbox.




Contents

Gmail and Google App Accounts

Hotmail and Windows Live accounts

Yahoo! Mail

Other Web mail systems

Retrieving only the new unread messages

Processing retrieved e-mail messages

Gmail and Google App Accounts

Before retrieving messages from Gmail accounts, you need to enable POP support for your account. You can do that by going to the settings page, click on the tab named Forwarding and POP/IMAP, and enable one of the POP options that exposes the messages in your mailbox either since ever or only from now on.

Options to enable POP3 support in Gmail mailboxes

Gmail POP3 server responds in the port 995 and it requires that you enable SSL/TLS encryption. The user name must be the account e-mail address including the domain part.


$pop3 = new pop3_class; $pop3->hostname = "pop.gmail.com"; $pop3->port = 995; $pop3->tls = 1; $user = "account@gmail.com"; $password = "account password";

Hotmail and Windows Live accounts

Accessing Hotmail accounts is similar to Gmail, except that it does not need to explicitly enable POP support in the Web interface.


$pop3 = new pop3_class; $pop3->hostname = "pop3.live.com"; $pop3->port = 995; $pop3->tls = 1; $user = "account@hotmail.com"; $password = "account password";

Yahoo! Mail

Currently, accessing Yahoo! Mail mailbox messages via POP3 is restricted to paying users of the Yahoo! Mail plus service. Other than that, most parameters are similar to Gmail and Hotmail, except that the user name should be just the account user name, thus without the @ character and the domain name.


$pop3 = new pop3_class; $pop3->hostname = "pop.mail.yahoo.com"; $pop3->port = 995; $pop3->tls = 1; $user = "account"; $password = "account password";

Other Web mail systems

This article only covers a few of the most popular Web mail systems. If you know how to configure the POP3 access to other popular mail systems, please post a comment to this article, so you can share that information for benefit of other readers.

Retrieving only the new unread messages

Some applications retrieve e-mail messages from a mailbox via POP3 but do not delete the messages. Therefore they cannot easily determine if the message was already retrieved or is new.

Unfortunately, the POP3 protocol does not provide a way to determine which messages in a mailbox are new or were already retrieved in a previous access.

One way to solve this problem is to keep track of the message identifiers of the messages read so far, for instance storing those identifiers in a database.

The POP3 class ListMessage function can list all the messages if you pass an empty string as first parameter. If you pass the value 1 as second parameter, it will return an array with the unique identifier of all messages.

If you lookup your database of previously retrieved messages and compare with the unique identifiers of the messages in the POP3 mailbox, you can easily determine which messages are new by finding the unique identifiers of messages not present in your database.

This is not a very efficient solution if you have many messages in your mailbox, so it may take a while, but at least it is a solution that works when you retrieve messages via POP3.

Processing retrieved e-mail messages

Once you retrieve the new messages, you need to process them eventually parsing the messages to extract their information. That is a task that can be easily achieved using a separate PHP MIME message parser class in conjunction with the POP3 class.

That is a subject that was already covered in a past post of this blog about processing incoming mail messages using PHP.

If you have doubts or questions about how to achieve other purposes with this class that you would like to be covered in eventual posts of this blog, feel free to post a comment to this article.




You need to be a registered user or login to post a comment

1,417,796 PHP developers registered to the PHP Classes site.
Be One of Us!

Login Immediately with your account on:

FacebookGmail
HotmailStackOverflow
GitHubYahoo


Comments:

10. integarte gmail and yahoo email into my web application - vishnu (2016-06-20 11:06)
email from gmail and yahoo... - 1 reply
Read the whole comment and replies

9. 0 message in gmail box - afpa (2015-10-27 00:01)
error with pop.gmail.com... - 1 reply
Read the whole comment and replies

6. Not Fetching Mail from Inbox - mohamad mantach (2013-12-19 21:03)
Not Fetching Mail from Inbox... - 1 reply
Read the whole comment and replies

5. ' - Devendra Kumar Rathore (2013-09-09 08:23)
'... - 0 replies
Read the whole comment and replies

4. what should be the base - bhutto (2012-12-12 12:17)
browse_mail.php or parse_message?... - 1 reply
Read the whole comment and replies

3. fashinefa - fashinefa (2011-10-14 09:50)
Ture Religion jeans for womens... - 0 replies
Read the whole comment and replies

2. Another Great PHP class - Barbushin Sergey (2011-05-13 11:33)
Another Great PHP class... - 0 replies
Read the whole comment and replies

1. How Often to Check Pop3 - Bob Cavezza (2011-05-12 22:48)
How often to check to make sure you don't miss messages... - 1 reply
Read the whole comment and replies




  Post a comment Post a comment   See comments See comments (16)   Trackbacks (0)  
  All package blogs All package blogs   POP3 e-mail client POP3 e-mail client   Blog POP3 e-mail client package blog   RSS 1.0 feed RSS 2.0 feed   Blog Retrieving e-mail mes...