/***************************************
** Title.........: HTML Mime Mail class (Cut down version)
** Version.......: 1.26
** Author........: Richard Heyes <richard.heyes@heyes-computing.net>
** Filename......: html_mime_mail.class
** Last changed..: 25/06/2000
** Notes.........: Based upon mime_mail.class
** by Tobias Ratschiller <tobias@dnet.it>
** and Sascha Schumann <sascha@schumann.cx>.
***************************************/
class html_mime_mail{
var $headers;
var $body;
var $multipart;
var $mime;
var $parts = array();
function html_mime_mail($headers = ''){
$this->headers = $headers;
}
function add_attachment($file, $name = '', $c_type = 'application/octet-stream'){
$this->parts[] = array( 'body' => $file,
'name' => $name,
'c_type' => $c_type );
}
function add_body_text($body){
$this->body = $body;
}
function build_body(){
$body = 'Content-Type: text/html'."\n";
$body .= 'Content-Transfer-Encoding: base64'."\n\n";
$body .= chunk_split(base64_encode($this->body))."\n";
return $body;
}
function build_part($i){
$message_part = '';
$message_part.= 'Content-Type: '.$this->parts[$i]['c_type'];
if($this->parts[$i]['name'] != '')
$message_part .= '; name="'.$this->parts[$i]['name']."\"\n";
else
$message_part .= "\n";
$message_part.= 'Content-Transfer-Encoding: base64'."\n";
$message_part.= 'Content-Disposition: attachment; filename="'.$this->parts[$i]['name']."\"\n\n";
$message_part.= chunk_split(base64_encode($this->parts[$i]['body']))."\n";
return $message_part;
}
function build_message(){
$boundary = '=_'.md5(uniqid(time()));
$this->headers.= "MIME-Version: 1.0\n";
$this->headers.= "Content-Type: multipart/mixed;".chr(10).chr(9)."boundary=\"".$boundary."\" \n";
$this->multipart = '';
$this->multipart.= "This is a MIME encoded message.\nCreated by html_mime_mail.class.\nSee
http://www.heyes-computing.net/ for a copy.\n\n";
$this->multipart .= '--'.$boundary."\n".$this->build_body();
for($i=(count($this->parts)-1); $i>=0; $i--){
$this->multipart.= '--'.$boundary."\n".$this->build_part($i);
}
$this->mime = $this->multipart."--".$boundary."--\n";
}
function send($to_name, $to_addr, $from_name, $from_addr, $subject = '', $headers = ''){
if($to_name != '') $to = '"'.$to_name.'" <'.$to_addr.'>';
else $to = $to_addr;
if($from_name != '') $from = '"'.$from_name.'" <'.$from_addr.'>';
else $from = $from_addr;
mail($to, $subject, $this->mime, 'From: '.$from."\n".$this->headers);
}
} // End of class.