PHP
  Home arrow PHP arrow Page 3 - Email Management Details
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 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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

Email Management Details
By: Sams Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2006-11-16

    Table of Contents:
  • Email Management Details
  • Attaching a File to a Message
  • Attached Images for HTML Emails
  • A Word About Email Delivery
  • Exam Prep Questions

  • 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


    Email Management Details - Attached Images for HTML Emails


    (Page 3 of 5 )

    HTML emails will attempt to download their images and stylesheets from your web server. Because of security and privacy reasons, many MUAs will refuse to attempt these downloads, ruining the look of your HTML email message.

    You can add your images as attachments to your email, and then point your HTML at the attached images:

    • Change the first Content-Type of your email to be multipart/related. Don't forget to include the boundary definition.

    • When you add an image as an attachment, include this additional header:

    • Content-Location: URL

    • URL is the URL that you use inside the <img> tag to include your image.

    <?php
    // who is the email going to?
    // change this to be *your* email address ;-)
    $to = "stuart";
    // what is the URL of the image?
    $image = http://static.php.net/http://www.php.net/
    images/php.gif; // what is the message? $message = "This is my fourth email sent from " . "<a
    href="http://www.php.net">PHP</a>.\r\n" . "This email has an image " . "<img src="" . $image . ""> here.\r\n"; // don't forget our blank line $blank_line = "\r\n"; // define our boundary $boundary_text = "php-12345"; $boundary = "—" . $boundary_text . "\r\n"; $last_boundary = " . $boundary_text . "—\r\n"; // add the MIME headers $more_headers = "MIME-Version: 1.0\r\n" . "Content-Type: multipart/related;
    boundary="" . $boundary_text . ""; type="text/html"\r\n"; // create the first part of the message $mime_message = "If you are reading this, it means
    that your e-mail client\r\n" . "does not support MIME. Please
    upgrade your e-mail client\r\n" . "to one that does support MIME.\r\n" . $boundary; // add the second part of the message $mime_message .= "Content-Type: text/html;
    charset="iso-8859-1"\r\n" . "Content-Transfer-Encoding:
    7bit\r\n" . $blank_line . $message . $boundary; // now add the attachment $mime_message .= "Content-Type: image/gif;
    name="php.gif"\r\n" . "Content-Transfer-Encoding:
    base64\r\n" . "Content-Location: " . $image . "\r\n" . $blank_line . chunk_split(base64_encode
    (file_get_contents("php.gif"))) . "\r\n" . $last_boundary; // send the email $result = mail ( $to, "My first HTML e-mail with an embedded
    image", $mime_message, $more_headers ); ?>

    Using Extra Command-Line Parameters

    The fifth argument to mail() is a list of parameters to use when executing the sendmail wrapper.

    These parameters have no effect at all if you are using PHP on Windows without a sendmail wrapper.

    More PHP Articles
    More By Sams Publishing


       · This article is an excerpt from the book "Zend PHP Certification Study Guide,"...
     

    Buy this book now. This article is excerpted from chapter 8 of the Zend PHP Certification Study Guide, written by Zend Technologies (Sams; ISBN: 0672327090). Check it out today at your favorite bookstore. Buy this book now.

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT