rendered paste body<?php
class MMail
{
var $hash;
var $from;
var $txt;
var $html;
var $file = array();
var $subject;
var $mimetypes;
function MMail()
{
$this->hash = md5(date('r', time()));
$this->create_array();
}
public function Msubject($subject)
{
$this->subject = $subject;
}
public function Mfrom($from)
{
$this->from = $from;
}
public function Mtxt($txt)
{
$buffer = "--727-alt-".$this->hash."\r\n"
."Content-Type: text/plain; charset=ISO-8859-1; format=flowed\r\n"
."Content-Transfer-Encoding: base64\r\n\r\n";
$buffer .= chunk_split(base64_encode($txt));
$buffer .= "\r\n\r\n";
$this->txt = $buffer;
}
public function Mhtml($txt)
{
$buffer = "--727-alt-".$this->hash."\r\n"
."Content-Type: text/html; charset=ISO-8859-1\r\n"
."Content-Transfer-Encoding: base64\r\n\r\n";
$buffer .= chunk_split(base64_encode($txt));
$buffer .= "\r\n\r\n--727-alt-".$this->hash."--\r\n\r\n";
$this->html = $buffer;
}
public function Mfile($file, $name)
{
//$fileinfo = "image/jpeg";
$fileinfo = $this->get_mimetype($name);
$attachment = chunk_split(base64_encode(file_get_contents($file)));
$buffer = "--727-mixed-".$this->hash."\r\n"
."Content-Type: ".$fileinfo."; name=\"".$name."\"\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-Disposition: attachment \r\n\r\n"
.$attachment;
array_push($this->file, $buffer);
return true;
}
private function getfiles()
{
$message = "";
if(count($this->file>0))
{
foreach($this->file as $key => $value)
{
$message .= $value;
if($key+1 == count($this->file))
$message .= "--727-mixed-".$this->hash."--\r\n";
//else
// $message .= "--727-mixed-".$this->hash."\r\n";
}
return $message;
}
else
{
return "";
}
}
private function make_headers()
{
$headers = "From: ".$this->from;
$headers .= "\r\nMIME-Version: 1.0";
$headers .= "\r\nReply-To: ".$this->from;
$headers .= "\r\nX-Mailer: MMail v1.0b";
if(count($this->file)>0)
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"727-mixed-".$this->hash."\"";
else
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"727-alt-".$this->hash."\"";
$headers .= "\r\nThis is a multi-part message in MIME format.\r\n";
return $headers;
}
private function compose_message()
{
if(count($this->file)>0)
{
$message = "--727-mixed-".$this->hash." \r\n"
."Content-Type: multipart/alternative; boundary=\"727-alt-".$this->hash."\"\r\n\r\n";
}
else
{
$message = "";
}
$message .= $this->txt;
if(empty($this->html))
{
$this->Mhtml(nl2br($this->txt));
}
$message .= $this->html;
$message .= $this->getfiles();
return $message;
}
public function send($to)
{
$headers = $this->make_headers();
$subject = $this->subject;
$message = $this->compose_message();
if(ereg("gmail",$to))
{
$headers = preg_replace("(\r)", "", $headers);
$message = preg_replace("(\r)", "", $message);
$subject = "Til Gmail";
}
$total = $headers.$message;
if(mail($to, $subject, "", $total, "-f".EMAIL))
return true;
else
return false;
}
private function get_mimetype($filename)
{
$filename = strtolower($filename);
for($i=1; substr($filename, -$i, 1) != "."; $i++);
$postfix = substr($filename, -$i+1);
if(array_key_exists($postfix, $this->mimetypes))
return $this->mimetypes[$postfix];
else
return "application/octet-stream";
}
private function create_array()
{
$mimetypes["ai"] = "application/postscript";
$mimetypes["aif"] = "audio/x-aiff";
$mimetypes["aifc"] = "audio/x-aiff";
$mimetypes["aiff"] = "audio/x-aiff";
$mimetypes["asc"] = "text/plain";
$mimetypes["au"] = "audio/basic";
$mimetypes["avi"] = "video/x-msvideo";
$mimetypes["bcpio"] = "application/x-bcpio";
$mimetypes["bin"] = "application/octet-stream";
$mimetypes["c"] = "text/plain";
$mimetypes["cc"] = "text/plain";
$mimetypes["ccad"] = "application/clariscad";
$mimetypes["cdf"] = "application/x-netcdf";
$mimetypes["class"] = "application/octet-stream";
$mimetypes["cpio"] = "application/x-cpio";
$mimetypes["cpt"] = "application/mac-compactpro";
$mimetypes["csh"] = "application/x-csh";
$mimetypes["css"] = "text/css";
$mimetypes["dcr"] = "application/x-director";
$mimetypes["dir"] = "application/x-director";
$mimetypes["dms"] = "application/octet-stream";
$mimetypes["doc"] = "application/msword";
$mimetypes["drw"] = "application/drafting";
$mimetypes["dvi"] = "application/x-dvi";
$mimetypes["dwg"] = "application/acad";
$mimetypes["dxf"] = "application/dxf";
$mimetypes["dxr"] = "application/x-director";
$mimetypes["eps"] = "application/postscript";
$mimetypes["etx"] = "text/x-setext";
$mimetypes["exe"] = "application/octet-stream";
$mimetypes["ez"] = "application/andrew-inset";
$mimetypes["f"] = "text/plain";
$mimetypes["f90"] = "text/plain";
$mimetypes["fli"] = "video/x-fli";
$mimetypes["gif"] = "image/gif";
$mimetypes["gtar"] = "application/x-gtar";
$mimetypes["gz"] = "application/x-gzip";
$mimetypes["h"] = "text/plain";
$mimetypes["hdf"] = "application/x-hdf";
$mimetypes["hh"] = "text/plain";
$mimetypes["hqx"] = "application/mac-binhex40";
$mimetypes["htm"] = "text/html";
$mimetypes["html"] = "text/html";
$mimetypes["ice"] = "x-conference/x-cooltalk";
$mimetypes["ief"] = "image/ief";
$mimetypes["iges"] = "model/iges";
$mimetypes["igs"] = "model/iges";
$mimetypes["ips"] = "application/x-ipscript";
$mimetypes["ipx"] = "application/x-ipix";
$mimetypes["jpe"] = "image/jpeg";
$mimetypes["jpeg"] = "image/jpeg";
$mimetypes["jpg"] = "image/jpeg";
$mimetypes["js"] = "application/x-javascript";
$mimetypes["kar"] = "audio/midi";
$mimetypes["latex"] = "application/x-latex";
$mimetypes["lha"] = "application/octet-stream";
$mimetypes["lsp"] = "application/x-lisp";
$mimetypes["lzh"] = "application/octet-stream";
$mimetypes["m"] = "text/plain";
$mimetypes["man"] = "application/x-troff-man";
$mimetypes["me"] = "application/x-troff-me";
$mimetypes["mesh"] = "model/mesh";
$mimetypes["mid"] = "audio/midi";
$mimetypes["midi"] = "audio/midi";
$mimetypes["mif"] = "application/vndmif";
$mimetypes["mime"] = "www/mime";
$mimetypes["mov"] = "video/quicktime";
$mimetypes["movie"] = "video/x-sgi-movie";
$mimetypes["mp2"] = "audio/mpeg";
$mimetypes["mp3"] = "audio/mpeg";
$mimetypes["mpe"] = "video/mpeg";
$mimetypes["mpeg"] = "video/mpeg";
$mimetypes["mpg"] = "video/mpeg";
$mimetypes["mpga"] = "audio/mpeg";
$mimetypes["ms"] = "application/x-troff-ms";
$mimetypes["msh"] = "model/mesh";
$mimetypes["nc"] = "application/x-netcdf";
$mimetypes["oda"] = "application/oda";
$mimetypes["pbm"] = "image/x-portable-bitmap";
$mimetypes["pdb"] = "chemical/x-pdb";
$mimetypes["pdf"] = "application/pdf";
$mimetypes["pgm"] = "image/x-portable-graymap";
$mimetypes["pgn"] = "application/x-chess-pgn";
$mimetypes["png"] = "image/png";
$mimetypes["pnm"] = "image/x-portable-anymap";
$mimetypes["pot"] = "application/mspowerpoint";
$mimetypes["ppm"] = "image/x-portable-pixmap";
$mimetypes["pps"] = "application/mspowerpoint";
$mimetypes["ppt"] = "application/mspowerpoint";
$mimetypes["ppz"] = "application/mspowerpoint";
$mimetypes["pre"] = "application/x-freelance";
$mimetypes["prt"] = "application/pro_eng";
$mimetypes["ps"] = "application/postscript";
$mimetypes["qt"] = "video/quicktime";
$mimetypes["ra"] = "audio/x-realaudio";
$mimetypes["ram"] = "audio/x-pn-realaudio";
$mimetypes["ras"] = "image/cmu-raster";
$mimetypes["rgb"] = "image/x-rgb";
$mimetypes["rm"] = "audio/x-pn-realaudio";
$mimetypes["roff"] = "application/x-troff";
$mimetypes["rpm"] = "audio/x-pn-realaudio-plugin";
$mimetypes["rtf"] = "text/rtf";
$mimetypes["rtx"] = "text/richtext";
$mimetypes["scm"] = "application/x-lotusscreencam";
$mimetypes["set"] = "application/set";
$mimetypes["sgm"] = "text/sgml";
$mimetypes["sgml"] = "text/sgml";
$mimetypes["sh"] = "application/x-sh";
$mimetypes["shar"] = "application/x-shar";
$mimetypes["silo"] = "model/mesh";
$mimetypes["sit"] = "application/x-stuffit";
$mimetypes["skd"] = "application/x-koan";
$mimetypes["skm"] = "application/x-koan";
$mimetypes["skp"] = "application/x-koan";
$mimetypes["skt"] = "application/x-koan";
$mimetypes["smi"] = "application/smil";
$mimetypes["smil"] = "application/smil";
$mimetypes["snd"] = "audio/basic";
$mimetypes["sol"] = "application/solids";
$mimetypes["spl"] = "application/x-futuresplash";
$mimetypes["src"] = "application/x-wais-source";
$mimetypes["step"] = "application/STEP";
$mimetypes["stl"] = "application/SLA";
$mimetypes["stp"] = "application/STEP";
$mimetypes["sv4cpio"] = "application/x-sv4cpio";
$mimetypes["sv4crc"] = "application/x-sv4crc";
$mimetypes["swf"] = "application/x-shockwave-flash";
$mimetypes["t"] = "application/x-troff";
$mimetypes["tar"] = "application/x-tar";
$mimetypes["tcl"] = "application/x-tcl";
$mimetypes["tex"] = "application/x-tex";
$mimetypes["texi"] = "application/x-texinfo";
$mimetypes["texinfo"] = "application/x-texinfo";
$mimetypes["tif"] = "image/tiff";
$mimetypes["tiff"] = "image/tiff";
$mimetypes["tr"] = "application/x-troff";
$mimetypes["tsi"] = "audio/TSP-audio";
$mimetypes["tsp"] = "application/dsptype";
$mimetypes["tsv"] = "text/tab-separated-values";
$mimetypes["txt"] = "text/plain";
$mimetypes["unv"] = "application/i-deas";
$mimetypes["ustar"] = "application/x-ustar";
$mimetypes["vcd"] = "application/x-cdlink";
$mimetypes["vda"] = "application/vda";
$mimetypes["viv"] = "video/vndvivo";
$mimetypes["vivo"] = "video/vndvivo";
$mimetypes["vrml"] = "model/vrml";
$mimetypes["wav"] = "audio/x-wav";
$mimetypes["wrl"] = "model/vrml";
$mimetypes["xbm"] = "image/x-xbitmap";
$mimetypes["xlc"] = "application/vndms-excel";
$mimetypes["xll"] = "application/vndms-excel";
$mimetypes["xlm"] = "application/vndms-excel";
$mimetypes["xls"] = "application/vndms-excel";
$mimetypes["xlw"] = "application/vndms-excel";
$mimetypes["xml"] = "text/xml";
$mimetypes["xpm"] = "image/x-xpixmap";
$mimetypes["xwd"] = "image/x-xwindowdump";
$mimetypes["xyz"] = "chemical/x-pdb";
$mimetypes["zip"] = "application/zip";
$this->mimetypes = $mimetypes;
}
}