<?php
class email
{
var $from;
var $to;
var $cc;
var $bcc;
var $subject;
var $body;
var $useragent;
var $attachedfiles;
function email($from,$to,$subject,$body,$cc="",$bcc="",$useragent="PHP/ReptilerEMailClass")
{
$this->from=$from;
$this->to=$to;
$this->subject=$subject;
$this->body=$body;
$this->cc=$cc;
$this->bcc=$bcc;
$this->useragent=$useragent;
$this->attachedfiles=array();
}
function addattachment($filename)
{
$this->attachedfiles[]=$filename;
}
function composemail()
{
if (count($this->attachedfiles)>0)
{
$boundary='----'.md5(uniqid());
}
$mail='To: '.$this->to."\r\n";
$mail.='Subject: '.$this->subject."\r\n";
$mail.="Content-class: urn:content-classes: message\r\n";
$mail.='User-Agent: '.$this->useragent."\r\n";
$mail.="MIME-Version: 1.0\r\n";
if (count($this->attachedfiles)>0)
{
$mail.="Content-Type: multipart/mixed;\r\n\tboundary=\"".$boundary."\"\r\n";
}
$mail.='From: '.$this->from."\r\n";
if (!empty($this->cc))
{
$mail.='Cc: '.$this->cc."\r\n";
}
if (!empty($this->bcc))
{
$mail.='Bcc: '.$this->bcc."\r\n";
}
$mail.="X-Priority: 3 (Normal)\r\n";
$mail.="Importance: Normal\r\n";
if (count($this->attachedfiles)>0)
{
$mail.="\r\n--".$boundary."\r\n";
}
$mail.="Content-Type: text/plain;\r\n\tcharset=\"iso-8859-1\"\r\n";
$mail.="Content-Transfer-Encoding: quoted-printable\r\n";
$mail.="Content-Disposition: inline\r\n\r\n";
$mail.=imap_8bit($this->body)."\r\n\r\n";
if (count($this->attachedfiles)>0)
{
for ($x=0;$x<count($this->attachedfiles);$x++)
{
$mail.="\r\n\r\n--".$boundary."\r\n";
$filename=explode('/',$this->attachedfiles[$x]);
$filename=$filename[count($filename)-1];
$file=fopen($this->attachedfiles[$x],"r");
$content=fread($file,filesize($this->attachedfiles[$x]));
fclose($file);
$encodedfile=chunk_split(base64_encode($content));
$mail.="Content-Type: application/octet-stream;\r\n\tname=\"".$filename."\"\r\n";
$mail.="Content-Transfer-Encoding: base64\r\n";
$mail.='Content-Description: '.$filename."\r\n";
$mail.="Content-Disposition: attachment;\r\n\tfilename=\"".$filename."\"\r\n\r\n";
$mail.=$encodedfile;
}
$mail.="\r\n\r\n--".$boundary."--";
}
return $mail;
}
}
?>