Source for file Email.php

Documentation is available at Email.php

  1. <?php
  2.  
  3. /**
  4.  * Send an HTML and/or text email
  5.  *
  6.  * This class can be used by any module as follows:-
  7.  * - $this->exec_module_action('Email', 'send_HTML_email', $from, $to, $subject, $html_data, $text_data);
  8.  */
  9. class Email {
  10.     /**
  11.      * Construct the email headers and send email using mail()
  12.      *
  13.      * @param string $from The from email address
  14.      * @param string $to The to email address
  15.      * @param string $subject The subject of the email
  16.      * @param string $html_data The HTML portion of the email (default: 0)
  17.      * @param string $text_data The text portion of the email (default: 0)
  18.      *
  19.      * @return Returns true if mail sent successfully, false otherwise
  20.      */
  21.     function send_HTML_email($from$to$subject$html_data=0$text_data=0{
  22.         $boundary md5(uniqid(rand()true));
  23.     
  24.         // Main headers
  25.         $headers 
  26.             "MIME-Version: 1.0\n" .
  27.             "From$from\n.
  28.             "Content-Typemultipart/alternativeboundary = $boundary\n\n.
  29.             "This is a MIME encoded message.\n\n";
  30.     
  31.         // HTML chunk
  32.         if ($html_data{
  33.             $headers .=
  34.                 "--$boundary\n.
  35.                 "Content-Type: text/html; charset=ISO-8859-1\n" .
  36.                 "Content-Transfer-Encoding: base64\n\n";
  37.  
  38.             $headers .= chunk_split(base64_encode($html_data));
  39.         }
  40.     
  41.         // Text chuck
  42.         if ($text_data{
  43.             // Plain text chunk
  44.             $headers .=
  45.                 "--$boundary\n.
  46.                 "Content-Type: text/plain; charset=ISO-8859-1\n" .
  47.                 "Content-Transfer-Encoding: base64\n\n";
  48.                 
  49.             $headers .= chunk_split(base64_encode($text_data));
  50.         }
  51.         
  52.         // Send email
  53.         return mail($to$subject""$headers);
  54.     }
  55. }
  56.  
  57. ?>

Documentation generated on Sat, 23 Jun 2007 21:28:19 -0500 by phpDocumentor 1.3.2