PHP
  Home arrow PHP arrow Page 2 - 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) - A Picture Is Worth A Thousand Words


    (Page 2 of 7 )

    The best way to understand how message attachments work is with an example. Consider the following email message, which contains no attachments,

    Return-Path: <jane@some.domain.com> Received: from localdomain (unknown [205.89.123.112]) by mail.domain.com (Postfix) with ESMTP id B0AYBHA41 for <john@some.domain.com>; Thu, 6 Dec 2001 21:05:51 +0530 (IST) Message-Id: <3.3.7.32.20011206210943.00b26d40@melonfire.com> Date: Thu, 06 Dec 2001 21:09:43 +0500 To: John Doe <john@some.domain.com> From: Jane Doe <jane@some.domain.com> Subject: Photos Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Do you still have those vacation photos with you? Send me a copy if you do. - Jane
    and then contrast it with this one, which does.

    Return-Path: <john@some.domain.com> Received: from localdomain (unknown [205.89.123.112]) by mail.domain.com (Postfix) with ESMTP id B0AYBHA41 for <jane@some.domain.com>; Thu, 6 Dec 2001 21:05:51 +0530 (IST) Message-Id: <3.0.3.32.20011207082225.006e927c@localhost> Date: Fri, 07 Dec 2001 08:22:25 +0500 To: Jane Doe <jane@some.domain.com> From: John Doe <john@some.domain.com> Subject: Re: Photos Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=====================_1007675545==_" --=====================_1007675545==_ Content-Type: text/plain; charset="us-ascii" Hi Jane, Find photos attached. John --=====================_1007675545==_ Content-Type: application/zip; name="photos1.zip"; x-mac-type="705A4950"; x-mac-creator="705A4950" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="photos1.zip" UEsDBBQAAAAIABythCvu1mnpugIAALsIAAALAAAAY29tcG9zZS5waHC1lltP2zAUx59Xqd/ -- snip -- AK6LAAAAAA== --=====================_1007675545==_ Content-Type: application/zip; name="photos2.zip"; x-mac-type="705A4950"; x-mac-creator="705A4950" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="photos2.zip" UEsDBBQAAAAIAACRDSux3m3PFwIAABsIAAAXAAAAc29hcGxpYi5zb2FwaW50ZXJvcC5waHC -- snip -- cFBLBQYAAAAACwALALcCAABRfQAAAAA= --=====================_1007675545==_--
    As you can see, the message containing attachments differs from the plaintext message in a couple of important ways.

    1. Since it consists of different parts (one for the body and one for each attachment), it's Content-Type: header specifies the message type as "multipart/mixed".

    Content-Type: multipart/mixed;
    2. The various message sections are demarcated by a boundary "marker"; this marker is unique to each message, and is defined in the main message header so that MIME-compliant mail clients can distinguish between the various message parts.

    Content-Type: multipart/mixed; boundary="=====================_1007675545==_"
    If you look at the example above, you'll see that, as specified in the message header, the boundary marker "=====================_1007675545==_" is used as a separator between the different parts of the message.

    3. Since the SMTP protocol cannot handle binary data, binary attachments - in this case, zip archives - must be encoded into a text representation using one of a number of different encoding methods. This information, together with information on the attachment type and original filename, appears in the header for each message section.

    Content-Type: application/zip; name="photos2.zip"; x-mac-type="705A4950"; x-mac-creator="705A4950" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="photos2.zip"
    This provides the mail client with all the information it needs to decode and display the attachment. It can use the Content-Transfer-Encoding: header to determine how best to decode the text block back into binary data, the filename to determine what the resulting file should be called, and the Content-Disposition: header to decide whether the binary data should be displayed as an attachment or within the message body.

    Note that this discussion is restricted to MIME attachments only. Other standards to handle mail attachments do exist. Take a look at http://www.faqs.org/rfcs/rfc2045.html for the MIME specification.

    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 5 hosted by Hostway