<?php
class email
{
var $id;
var $to;
var $subject;
var $body;
var $from;
var $cc;
var $bcc;
var $attachedfiles;
function quoted_printable($string)
{
$crlf = "\n" ;
$string = preg_replace('!(\r\n|\r|\n)!', $crlf, $string) . $crlf ;
$f[] = '/([\000-\010\013\014\016-\037\075\177-\377])/e' ;
$r[] = "'=' . sprintf('%02X', ord('\\1'))" ;
$f[] = '/([\011\040])' . $crlf . '/e' ;
$r[] = "'=' . sprintf('%02X', ord('\\1')) . '" . $crlf . "'" ;
$string = preg_replace($f, $r, $string) ;
return trim(wordwrap($string, 70, ' =' . $crlf)) ;
}
function __construct($to,$subject,$body,$from="",$cc="",$bcc="")
{
$this->id=md5(uniqid());
$this->to=$to;
$this->subject=$subject;
$this->body=$body;
$this->from=$from;
$this->cc=$cc;
$this->bcc=$bcc;
$this->attachedfiles=array();
}
function destroy()
{
if (file_exists("mailtemp/".$this->id))
{
for ($attachment=0;$attachment<count($this->attachedfiles);$attachment++)
{
unlink("mailtemp/".$this->id."/".$this->attachedfiles[$attachment]);
}
rmdir("mailtemp/".$this->id);
}
}
function attachfile($tempfile,$filename)
{
if (!file_exists("mailtemp/".$this->id))
{
mkdir("mailtemp/".$this->id);
}
move_uploaded_file($tempfile,"mailtemp/".$this->id."/".$filename);
$this->attachedfiles[]=$filename;
}
function removeattachment($filename)
{
unlink("mailtemp/".$this->id."/".$filename);
$newattachedfiles=array();
for ($attachment=0;$attachment<count($this->attachedfiles);$attachment++)
{
if ($this->attachedfiles[$attachment]!=$filename)
{
$newattachedfiles[]=$this->attachedfiles[$attachment];
}
}
$this->attachedfiles=$newattachedfiles;
unset($newattachedfiles);
}
function send()
{
$body=quoted_printable($this->body);
$body.="\n\n";
$boundary="----".$this->id;
$email="info@trempe3.com";
$email.="Content-class: urn:content-classes:message";
$email.="\nUser-Agent: Free WebMail";
$email.="\nMIME-Version: 1.0";
if (!empty($this->attachedfiles))
{
$email.="\nContent-Type: multipart/mixed;\n\tboundary=\"".$boundary."\"";
}
if (!empty($this->from))
{
$email.="\nFrom: ".$this->from;
}
if (!empty($this->cc))
{
$email.="\nCc: ".$this->cc;
}
if (!empty($this->bcc))
{
$email.="\nBcc: ".$this->bcc;
}
$email.="\nX-Priority: 3 (Normal)";
$email.="\nImportance: Normal";
if (!empty($this->attachedfiles))
{
$email.="\n\n--".$boundary;
}
$email.="\nContent-Type: text/plain;\n\tcharset=\"iso-8859-1\"";
$email.="\nContent-Transfer-Encoding: quoted-printable";
$email.="\nContent-Disposition: inline";
$email.="\n\n".$body;
if (!empty($this->attachedfiles))
{
$email.="\n\n--".$boundary;
}
for ($attachment=0;$attachment<count($this->attachedfiles);$attachment++)
{
$file=fopen("mailtemp/".$this->id."/".$this->attachedfiles[$attachment],"r");
$content=fread($file,filesize("mailtemp/".$this->id."/".$this->attachedfiles[$attachment]));
fclose($file);
$encodedfile=chunk_split(base64_encode($content));
$email.="\nContent-Type: application/octet-stream;\n\tname=\"".$this->attachedfiles[$attachment]."\"";
$email.="\nContent-Transfer-Encoding: base64";
$email.="\nContent-Description: ".$this->attachedfiles[$attachment];
$email.="\nContent-Disposition: attachment;\n\tfilename=\"".$this->attachedfiles[$attachment]."\"";
$email.="\n\n".$encodedfile."\n\n--".$boundary;
}
if (!empty($this->attachedfiles))
{
$email.="--";
}
mail($this->to,$this->subject,"",$email);
}
}
function mailstring($mailobject)
{
return rawurlencode(serialize($mailobject));
}
function mailobject($mailstring)
{
return unserialize(stripslashes(rawurldecode($mailstring)));
}
?>