PHP
  Home arrow PHP arrow Page 2 - Sending Email with PHP Networking
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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

Sending Email with PHP Networking
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 3
    2008-09-15


    Table of Contents:
  • Sending Email with PHP Networking
  • Sending mail with PHP
  • Application Code
  • Code Examined
  • Sending Mail using the PEAR::Mail

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    Sending Email with PHP Networking - Sending mail with PHP
    ( Page 2 of 5 )

    Now that we know what tools PHP provides, let's write a quick application that will help us send messages with attachments. In order to send a message with an attachment, you need to send a mail header instructing that the email be sent as an attachment. A header might look like this:


    Content-disposition: attachment; filename=myfile.doc


    The header instructs the email to send the message as an attachment with a file called myfile.doc. So if you want to send a short message with an attachment, this is how it could look:


    <?php

    $to = " esme@holidays.com ";

    $subject= "Lunch?";

    $message = "This is my first test of the mail() function.";

    $headers = "Content-disposition: attachment;

    filename=myfile.docn";

    $headers .= "cc:salles@mycompany.comn";

    $result=mail($to, $subject, $message, $headers);

    ?>

    Another very important step that you need to take when sending attachments is to set the content type for the file. The following are the available content types:

    • image/gif
    • image/jpeg
    • audio/x-wav
    • audio/vnd.rn-realaudio
    • video/mpeg
    • video/avi

    You also may want to send application files. Some are text files, and some are binary files. For example, an RTF file is a text file, whereas a Word document is a binary file. Generally binary files are of type applica/octed stream. Binary files require encoding when they are sent through an email. PHP provides us with a function called chunk_split(), that does just that:


    $encode = chunk_split(base64_encode($string));


    In addition, when sending an encoded file, you need to inform the mail software that you intend to sent a encoded file. This is done in the headers section of the mail function:


    Content-Transfer-Encoding: base64



     
     
    >>> More PHP Articles          >>> More By David Web
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT