PHP
  Home arrow PHP arrow Page 3 - Building A PHP-Based Mail Client (part...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Building A PHP-Based Mail Client (part 2)
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 11
    2002-01-11

    Table of Contents:
  • Building A PHP-Based Mail Client (part 2)
  • A Picture Is Worth A Thousand Words
  • The Way Things Work
  • Structure And Syntax
  • Room With A View
  • Getting Down
  • Miles To Go

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Building A PHP-Based Mail Client (part 2) - The Way Things Work


    (Page 3 of 7 )

    After a little research, it quickly becomes apparent that a standard process flow can be developed for attachment handling, both while sending and reading mail. Here's my first draft of the process:

    When reading email,

    1. Check the message's Content-Type: header and count the number of message parts.

    If the Content-Type: header indicates that the message is in plaintext, you can skip ahead to the last step. If it's anything but "text/plain", it's a fair bet that you'll have to parse it further.

    An alternative here would be to parse the message body and count how many parts it's divided into - if it's two or more, you can again expect to have to parse it further.

    2. Parse the message body.

    If the message is a multipart message - for example, the type "multipart/mixed" - it is necessary to parse the various sections of the message to determine the attachment attributes.

    As explained previously, every message section includes a header providing information on the data enclosed within that section. This data is used by the mail client to figure out how to handle that particular section.

    3. Display the message section(s).

    Once the client has sufficient information on the number and type of attachments, the final step is to display each section. Plaintext sections can be displayed as is; encoded sections may need to be decoded and then displayed. If the client supports HTML-encoded mail - as most Web-based clients do - it may need to jump through a few additional hoops to decode and render embedded HTML markup.

    It's important to note that different mail clients handle multipart messages differently. Some clients display each section as is (raw text) without processing it further; others use the encoding information present in the section header to decode and display each section separately. Some clients display each message section as an attachment, while others use the data type of each section to decide whether the decoded section should be displayed inline (within the message body) or as an attachment.

    What about sending email? Well, that's also fairly simple - all you need to do is build a message incrementally, with each part representing an attachment and a boundary marker separating the various parts.

    1. Build the message headers.

    When sending email, the first step is to build the message headers. Some of these headers are built in response to user input - for example, the subject line and recipient addresses - while others must be added by the client itself. Typically, if one or more message attachments exist, the client will need to alter the Content-Type: of the message and generate a boundary marker to demarcate the various message sections.

    2. Add the message body and attachments.

    Once the headers have been built, the next step is to add the message text. If attachments exist, they must be encoded into plaintext and appended to the message body, with the message's unique boundary marker separating the various sections from each other.

    3. Send the message.

    With the headers and body both ready, the final task is to actually connect to a mail server and send the mail out. Some programming languages (like PHP) offer high-level constructs to perform this function; others require you to use low-level constructs to open up a socket connection to the server and send the message using socket communication techniques.

    More PHP Articles
    More By icarus, (c) Melonfire


     

       

    PHP ARTICLES

    - Validating Web Forms with the Code Igniter P...
    - Output Buffering
    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway