I will repost an article "transfer a file via EMAIL attachment (via mail )"
Last Update:2018-04-06
Source: Internet
Author: User
? ** Classmime_mail * OriginalimplementationbySaschaSchumannsascha@schumann.cx * ModifiedbyTobiasRatschillertobias@dnet.it :*
/*
* Class mime_mail
* Original implementation by Sascha Schumann <sascha@schumann.cx>
* Modified by Tobias Ratschiller <tobias@dnet.it>:
*-General code clean-up
*-Separate body-and from-property
*-Killed some mostly un-necessary stuff
*/
Class mime_mail
{
Var $ parts;
Var $;
Var $ from;
Var $ headers;
Var $ subject;
Var $ body;
/*
* Void mime_mail ()
* Class constructor
*/
Function mime_mail ()
{
$ This-> parts = array ();
$ This-> to = "";
$ This-> from = "";
$ This-> subject = "";
$ This-> body = "";
$ This-> headers = "";
}
/*
* Void add_attachment (string message, [string name], [string ctype])
* Add an attachment to the mail object
*/
Function add_attachment ($ message, $ name = "", $ ctype = "application/octet-stream ")
{
$ This-> parts [] = array (
"Ctype" => $ ctype,
"Message" => $ message,
"Encode" => $ encode,
"Name" => $ name
);
}
/*
* Void build_message (array part =
* Build message parts of an multipart mail
*/
Function build_message ($ part)
{
$ Message = $ part ["message"];
$ Message = chunk_split (base64_encode ($ message ));
$ Encoding = "base64 ";
Return "Content-Type:". $ part ["ctype"].
($ Part ["name"]? "; Name = \" ". $ part [" name "]." \ "": "").
"\ NContent-Transfer-Encoding: $ encoding \ n $ message \ n ";
}
/*
* Void build_multipart ()
* Build a multipart mail
*/
Function build_multipart ()
{
$ Boundary = "B". md5 (uniqid (time ()));
$ Multipart = "Content-Type: multipart/mixed; boundary = $ boundary \ n \ nThis is a MIME
Encoded message. \ n -- $ boundary ";
For ($ I = sizeof ($ this-> parts)-1; $ I >=0; $ I --)
{
$ Multipart. = "\ n". $ this-> build_message ($ this-> parts [$ I]). "-- $ boundary ";
}
Return $ multipart. = "-- \ n ";
}
/*
* Void send ()
* Send the mail (last class-function to be called)
*/
Function send ()
{
$ Mime = "";
If (! Empty ($ this-> from ))
$ Mime. = "From:". $ this-> from. "\ n ";
If (! Empty ($ this-> headers ))
$ Mime. = $ this-> headers. "\ n ";
If (! Empty ($ this-> body ))
$ This-> add_attachment ($ this-> body, "", "text/plain ");
$ Mime. = "MIME-Version: 1.0 \ n". $ this-> build_multipart ();
Mail ($ this-> to, $ this-> subject, "", $ mime );
}
}; // End of class
/*
* Example usage
*
$ Attachment = fread (fopen ("test.jpg", "r"), filesize ("test.jpg "));
$ Mail = new mime_mail ();
$ Mail-> from = "foo@bar.com ";
$ Mail-> headers = "Errors-To: foo@bar.com ";
$ Mail-> to = "bar@foo.com ";
$ Mail-> subject = "Testing ...";
$ Mail-> body = "This is just a test .";
$ Mail-> add_attachment ("$ attachment", "test.jpg", "image/jpeg ");
$ Mail-> send ();
*/
?>