HomePHP Page 2 - Building A PHP-Based Mail Client (part 1)
Requiring Immediate Attention - PHP
Ever wondered how Web-based mail clients work, or what happens toyour email after you hit the "Send" button? This three-part case studydelves into the wild and wacky world of Web-based email applications, usingPHP's built-in POP3 functions to build an email client suitable forrerieving POP3 email via a Web browser. In this introductory segment -connecting to a POP3 server, logging in and out, retrieving message headersfor display, and deleting messages off the server.
Before we get into the nitty-gritty of syntax and structure, it's important to first put down the requirements of the software to be designed. This is a sometimes-tedious but always-necessary precedent to actual implementation of any software project, as it simultaneously offers a "big picture" view of the entire project and also provides a reference for the actual code development.
Typically, the software requirements are obtained after an analysis of the problems faced by the customer - an intensive, frequently-frustrating process involving large amounts of caffeine. In this specific case, though, I was able to arrive at the requirements after a fairly short conversation with the customer, during which the following problems became clear:
1. Members of the customer's sales team were frequently on the road chasing down leads. During this period, they had no way of accessing their internal corporate mail. The customer was looking for a tool that would allow employees to get to their mail even if they weren't physically at the workplace.
2. A number of the customer's employees were part-time or freelance workers, who came to the office only occasionally. Rather than assign these part-timers a dedicated computer each, the customer wanted to assign them a single "guest" machine, which could be used by them whenever they came in to work. A Web-based mail solution would be useful here too, as it would allow different users to use a single machine to read their mail.
The customer's evaluation of his problems has led him to conclude that he needed a simple Web-based mail client, along the lines of Hotmail (http://www.hotmail.com) or Mail.com (http://www.mail.com). Consequently, the brief was simple enough: a mail client which supported the standard feature set of Windows mail clients like Eudora and Microsoft Outlook, yet was accessible via a Web browser.
After a little research, I came up with the following list of software requirements (which was eventually approved by the customer):
1. The application must be capable of connecting to any POP3-compatible mail server (IMAP support was not a requirement) and retrieving a list of messages for a user-specified mailbox on that server. This message list must display important message headers - the sender, subject and size - together with (optionally) an attachment icon.
2. The application must be capable of displaying the contents of any message from the message list.
3. The application must allow the user to create and send a new email message (to multiple recipients simultaneously, if required)
4. The application must allow the user to reply to any message.
5. The application must allow the user to forward any message, with the option to include all, some or none of the message's original attachments.
6. The application must allow the user to delete any message from the server.
7. The application must support mail attachments, and allow the user to download these to his local workstation, or upload them for attachment to a new message.
This is a fairly standard feature set, and you'll find that almost every mail client allows you to perform these actions. Note that the list above is somewhat abridged - the actual requirements document was a bit more detailed, and included some additional items that will not be discussed here - but it still has enough material to give you a fairly good idea of what I'll be covering in this case study.
Putting down software requirements is a good starting point for any project, both from the implementation point of view and for other, related activities. Once the requirements are written down and approved by the customer, the developer can begin thinking about how to design and code the application, the interface designer can begin work on the application's user interface, and the QA team can begin building test cases to verify the final release of the code.