Specifications
Building Practical PHP and MySQL Projects
P
ART V
618
More and more often these days, sites want to offer Web-based email to their users. This chap-
ter explains how to implement a Web interface to an existing mail server using the PHP IMAP
library. You can use it to check your own existing mailbox through a Web page, or perhaps
extend it to support many users for mass Web-based email like Hotmail.
In this project, we will build an email client, Warm Mail, that will enable users to
• Connect to their accounts on POP3 or IMAP mail servers
• Read mail
• Send mail
• Reply to mail messages
• Forward mail messages
• Delete mail from their accounts
The Problem
In order for a user to be able to read his mail, we will need to find a way to connect to his mail
server. This generally won’t be the same machine as the Web server.
We will need a way to interact with his mailbox, to see what messages have been received and
to deal with each message individually.
Two main protocols are supported by mail servers for reading user mailboxes: POP3 and IMAP.
If possible, we should support both of these. POP3 stands for Post Office Protocol version 3,
and IMAP stands for Internet Message Access Protocol.
The main difference between these two is that POP3 is intended for, and usually used by, people
who connect to a network for a short time to download and delete their mail from a server. IMAP
is intended for online use, to interact with mail permanently kept on the remote server. IMAP has
some more advanced features that we won’t use here.
If you are interested in the differences between these protocols, you can consult the RFCs for
them (RFC 1939 for POP version 3 and RFC 2060 for IMAP version 4 rev1). An excellent
article comparing the two can be found at
http://www.imap.org/papers/imap.vs.pop.brief.html
Neither of these protocols is designed for sending mail—for that we must use the SMTP
(Simple Mail Transfer Protocol), which we have used before from PHP via the
mail() func-
tion. This protocol is described in RFC 821.
33 7842 CH27 3/6/01 3:41 PM Page 618










