A
Anonymous
Guest
Hey guys,
Couldn't sleep last knight, stupid storm woke me up at like 3, so i wrote a random class, a mail class with a capability of attatching a file to it. Hope it works, and someone has a use for it... Actually the idea came from an e-mail subscription, but there were parts that i had to modify and rewrite, if anyone has comments or anything that they can think of to add on to this class (or correct it, because i din't have time to go through it after i wrote it and there might be mistakes because i was sleepy
, it was early, i had to leave at 6 and i couldn't sleep) please feel free to share.
P.S. Apparently
Couldn't sleep last knight, stupid storm woke me up at like 3, so i wrote a random class, a mail class with a capability of attatching a file to it. Hope it works, and someone has a use for it... Actually the idea came from an e-mail subscription, but there were parts that i had to modify and rewrite, if anyone has comments or anything that they can think of to add on to this class (or correct it, because i din't have time to go through it after i wrote it and there might be mistakes because i was sleepy

Code:
<?php
class mail
{
$from;
$to;
$header;
$body;
function mail()
{
$this -> from = "";
$this -> to = "";
$this -> body = "";
$this -> header = Array();
$this -> subject = "";
}
function attach_file($file_name = "" , $file_content,$encoding_type = "application/octet-stream")
{
$this -> header[] = array(
"name" => $file_name,
"content" => $file_content,
"encode" => $encoding_type);
}
function build_letter($header)
{
$letter = $header["content"];
if ($header["encode"] != "text/plain")
{
$letter = chunk_split(base64_encode($letter));
$encoding = "base64";
}
else
$encoding = $header["encode"];
return "Content-Type: ".$header["encode"]. ($header["name"]? ";
$name = \"".$header["name"]."\"" : "") ."\r\nContent-Transfer-Encoding: $encoding\r\n\r\n$letter\n";
}
function set_multipart_mail()
{
$boundry = 'b'.md5(uniqid(time()));
$multipart = "Content-Type: multipart/mixed;
boundry =$boundary\n\nThis is a MIME encoded letter\r\n\r\n--$boundry";
for($step = sizeof($this->header)-1; $step >=0; $step--)
{
$multipart .= "\r\n".$this->build_letter($this->header[$step])."--$boundary";
}
return $multipart .= "--\r\n";
}
function get_full_message()
{
$mime = "";
if (!empty($this->from)):
$mime .= "From: ".$this->from." \r\n";
if (!empty($this->body)):
{
$this -> attach_file("",$this->body,"text/plain");
$mime .= "MIME-Version: 1.0\r\n".$this->set_multipart_mail();
}
return $mime;
}
function send_mail()
{
$mime = $this -> get_full_message(false);
mail($this->to,$this->subject,"",$mime);
}
}
?>
P.S. Apparently
PHP:
tags are not working anymore... I miss them, they were so useful in the past.