HomePHP Page 8 - Building A PHP-Based Mail Client (part 3)
Game Over - PHP
This third (and final) segment of our case study discusses theprocess of sending MIME-encoded email, demonstrating how to compose,forward and reply to email through a Web browser. It also discusses, indetail, the process of constructing a MIME-encoded message withattachments, explains PHP's HTTP upload capabilities, and examines thestandard error handler used throughout this case study.
And that's about it for this case study. We've covered a whole range of different things over the past couple of weeks - session management, HTTP headers and file upload, code modularization, MIME attachments, mail server connection and message retrieval, and a whole lot more - and I hope you found the process interesting and entertaining.
This case study, though slightly longer than usual, also demonstrates that application development for the Web requires a great deal more than just a knowledge of PHP. In order to develop an efficient, scalable and error-free Web application, developers must have a fundamental understanding of the protocols and design principles of the Internet, and must be able to apply this knowledge judiciously, always selecting the technology and approach that is optimal for a particular situation.
This is no easy task - it can take years to develop this approach - but the pay-off, both in terms of better-designed code and an overall feeling of satisfaction, is well worth it. Putting together this mail client was, at times, a frustrating exercise in trial and error, but I've come out the other end with a greater understanding of how email works, and a greater respect for the people whose job involves designing and implementing email solutions.
I found the following resources invaluable during the development process - if you're interested in learning more about the various topics discussed in this case, you should make it a point to visit them:
It should be noted at this point that this project is by no means complete. Since this prototype was introduced for internal use a few days back, a number of minor bugs have been reported, and some additional capabilities requested. Consequently, the source code provided in this article should be treated as pre-release code, unsuitable for use in production environments; I still have a ways to go before releasing this as a product to our customer.
Among the features requested: the ability to upload multiple attachments at a time; to support HTML-encoded messages; to allow sorting of the message listing by name, size, date and owner; to allow for group replies; to limit the number of files displayed per page; to change the default colours; and to display the name of the currently logged-in user. Unusual MIME attachments also tend to result in unpredictable behaviour - again, this is something that I need to debug and tune further.
I plan to continue adding features and optimizing code as and when time permits - if you'd like to give me a hand, or have ideas on how to improve the techniques discussed here, drop me a line and let me know. Ciao!
Note: All examples in this article have been tested on Linux/ig86 with Apache 1.3.12 and PHP 4.0.6. Examples are illustrative only, and are not meant for a production environment. Melonfire provides no warranties or support for the source code described in this article. YMMV!