<? Php
Class AttachmentMail {
Private $ from = 'Yours @ email.com ';
Private $ from_name = 'Your Name ';
Private $ reply_to = 'Yours @ email.com ';
Private $ to = '';
Private $ subject = '';
Private $ message = '';
Private $ attachment = '';
Private $ attachment_filename = '';
Public function _ construct ($ to, $ subject, $ message, $ attachment = '', $ attachment_filename = ''){
$ This-> to = $;
$ This-> subject = $ subject;
$ This-> message = $ message;
$ This-> attachment = $ attachment;
$ This-> attachment_filename = $ attachment_filename;
}
Public function mail (){
If (! Empty ($ this-> attachment )){
$ Filename = empty ($ this-> attachment_filename )? Basename ($ this-> attachment): $ this-> attachment_filename;
$ Path = dirname ($ this-> attachment );
$ Mailto = $ this->;
$ From_mail = $ this-> from;
$ From_name = $ this-> from_name;
$ Replyto = $ this-> reply_to;
$ Subject = $ this-> subject;
$ Message = $ this-> message;
$ File = $ path. '/'. $ filename;
$ File_size = filesize ($ file );
$ Handle = fopen ($ file, "r ");
$ Content = fread ($ handle, $ file_size );
Fclose ($ handle );
$ Content = chunk_split (base64_encode ($ content ));
$ Uid = md5 (uniqid (time ()));
$ Name = basename ($ file );
$ Header = "From:". $ from_name. "<". $ from_mail. "> ";
$ Header. = "Reply-To:". $ replyto ."";
$ Header. = "maid: 1.0 ";
$ Header. = "Content-Type: multipart/mixed; boundary =" ". $ uid .""";
$ Header. = "This is a multi-part message in MIME format .";
$ Header. = "--". $ uid ."";
$ Header. = "Content-type: text/plain; charsets = iso-8859-1 ";
$ Header. = "Content-Transfer-Encoding: 7bit ";
$ Header. = $ message ."";
$ Header. = "--". $ uid ."";
$ Header. = "Content-Type: application/octet-stream; name =" ". $ filename." "; // use diff. tyoes here
$ Header. = "Content-Transfer-Encoding: base64 ";
$ Header. = "Content-Disposition: attachment; filename =" ". $ filename .""";
$ Header. = $ content ."";
$ Header. = "--". $ uid ."--";
If (mail ($ mailto, $ subject, "", $ header )){
Return true;
} Else {
Return false;
}
} Else {
$ Header = "From:". ($ this-> from_name). "<". ($ this-> from). "> ";
$ Header. = "Reply-To:". ($ this-> reply_to )."";
If (mail ($ this-> to, $ this-> subject, $ this-> message, $ header )){
Return true;
} Else {
Return false;
}
}
}
}
?>
Call method
<? Php
Require ('email-Attachment. Php ');
$ Sendit = new AttachmentEmail ('Marry @ example.com ', 'Merry Christmas! ', 'Hi','/home/racker/gift.jpg ');
$ Sendit-> mail ();
?>