? Phpif(basename($php_self?class.html _ mime_mail.inc) {includefileinfo. inc; echopre if not included: $ mailnewhtml_mime_mail (); $ htmlHTML content; $ mail-add_html ($ html, $ text); $ mail-build_message (); $ mail-send (recipient, email receiving, sender, and sender If (basename ($ PHP_SELF) = "class.html _ mime_mail.inc ")
{
Include "fileinfo. inc ";
Echo"
If not:
\ $ Mail = new html_mime_mail ();
\ $ Html = \ "HTML content \";
\ $ Mail-> add_html (\ $ html, \ $ text );
\ $ Mail-> build_message ();
\ $ Mail-> send (recipient, Email recipient, Sender, Email sender, subject, external Header );
If zookeeper is included:
\ $ Url = \ "www.cuti.com. my/AD/\"; // What is the second bit? FONT color = "#007700"> }? FONT color = "#007700">} no http header: // The end of the header has a diagonal line.
\ $ Path = \ "/MAIL/AD/\"; // There is an oblique link at the end of the zookeeper.
\ $ Filename1 = 'a.jpg ';
\ $ Backgrnd1 = fread (\ $ fp = fopen (\ $ path. \ $ filename1, 'r'), filesize (\ $ path. \ $ filename1 ));
Fclose (\ $ fp );
... According to this type...
\ $ Filename6 = 'f.gif ';
\ $ Backgrnd6 = fread (\ $ fp = fopen (\ $ path. \ $ filename6, 'r'), filesize (\ $ path. \ $ filename6 ));
Fclose (\ $ fp );
\ $ Mail-> add_html_image (\ $ backgrnd1, \ $ filename1, 'image/jpeg ', 'http: //'. \ $ url. \ $ filename1 );
... According to this type...
\ $ Mail-> add_html_image (\ $ backgrnd6, \ $ filename6, 'image/GIF', 'http: // '. \ $ url. \ $ filename6 );
\ $ Mail = new html_mime_mail ();
\ $ Html = \ "HTML content inclusion \";
\ $ Mail-> add_html (\ $ html, \ $ text );
\ $ Mail-> build_message ();
\ $ Mail-> send (recipient, Email recipient, Sender, Email sender, subject, external Header );
";
}
/***************************************
** Title ......: HTML Mime Mail class
** Version ......: 1.26
** Author ......: Richard Heyes
** Filename...: html_mime_mail.class
** Last changed...: 25/06/2000
** Notes ......: Based upon mime_mail.class
** By Tobias Ratschiller
** And Sascha Schumann
.
**-Thanks to Thomas Flemming for supplying a fix
** For Win32.
**-Made headers terminated by CRLF instead of LF, now
** Compliant with RFC822. Thanks to Pao-Hsi Huang.
**-Fixed bug; certain mail systems (gmx.net in particle)
** Were rejecting mail because of a space character either
** Side of the equal sign on the boundary line. Thanks
** Peter Holland for policying me.
**-Fixed bug; $ html_images was tested to be an array or not
** But was set to be an array during object creation, so
** Test always returned true. Thanks to Bob Silva
** Policying me.
**-Fixed bug; when looping with $ obj-> send (), From: headers
** Were accumulating. Bummer. Thanks to Lance Rasmussen
** Policying me.
**-See http://www.heyes-computing.net/scripts/ for a zip/tar
** Containing an example script.
***************************************/
Class html_mime_mail {
Var $ headers;
Var $ body;
Var $ multipart;
Var $ mime;
Var $ html;
Var $ html_text;
Var $ html_images = array ();
Var $ cids = array ();
Var $ do_html;
Var $ parts = array ();
/***************************************
** Constructor function. Sets the headers
** If supplied.
***************************************/
Function html_mime_mail ($ headers = '){
$ This-> headers = $ headers;
}
/***************************************
** Adds a html part to the mail.
** Also replaces image names
** Content-id's.
***************************************/
Function add_html ($ html, $ text ){
$ This-> do_html = 1;
$ This-> html = $ html;
$ This-> html_text = $ text;
If (is_array ($ this-> html_images) AND count ($ this-> html_images)> 0 ){
/* For ($ I = 0; $ I
Html_images); $ I ++ ){
$ This-> html = ereg_replace ($ this-> html_images [$ I] ['name'], 'cid :'. $ this-> html_images [$ I] ['CID'], $ this-> html );
}
*/
}
}
/***************************************
** Builds html part of email.
***************************************/
Function build_html ($ orig_boundary ){
$ Sec_boundary = '= _'. md5 (uniqid (time ()));
$ Thr_boundary = '= _'. md5 (uniqid (time ()));
If (count ($ this-> html_images) = 0 ){
$ This-> multipart. = '--'. $ orig_boundary. "\ n ";
$ This-> multipart. = 'content-Type: multipart/alternative ;'. chr (10 ). chr (9 ). 'boundary = "'. $ sec_boundary. "\" \ n ";
// Ttj added below
$ This-> multipart. = '--'. $ thr_boundary. "\ n ";
$ This-> multipart. = 'content-Type: text/plain '. "\ n ";
$ This-> multipart. = $ this-> html_text. "\ n ";
$ This-> multipart. = '--'. $ thr_boundary. "-- \ n ";
// Ttj added above
$ This-> multipart. = '--'. $ sec_boundary. "\ n ";
$ This-> multipart. = 'content-Type: text/plain '. "\ n ";
$ This-> multipart. = 'content-Transfer-Encoding: base64'. "\ n ";
$ This-> multipart. = chunk_split (base64_encode ($ this-> html_text). "\ n ";
// Ttj added below
$ This-> multipart. = '--'. $ thr_boundary. "\ n ";
$ This-> multipart. = 'content-Type: text/html'. "\ n ";
$ This-> multipart. = $ this-> html. "\ n ";
$ This-> multipart. = '--'. $ thr_boundary. "-- \ n ";
// Ttj added above
$ This-> multipart. = '--'. $ sec_boundary. "\ n ";
$ This-> multipart. = 'content-Type: text/html'. "\ n ";
$ This-> multipart. = 'content-Transfer-Encoding: base64'. "\ n ";
$ This-> multipart. = chunk_split (base64_encode ($ this-> html). "\ n ";
$ This-> multipart. = '--'. $ sec_boundary. "-- \ n ";
} Else {
$ This-> multipart. = '--'. $ orig_boundary. "\ n ";
$ This-> multipart. = 'content-Type: multipart/related ;'. chr (10 ). chr (9 ). 'boundary = "'. $ sec_boundary. "\" \ n ";
$ This-> multipart. = '--'. $ sec_boundary. "\ n ";
$ This-> multipart. = 'content-Type: multipart/alternative ;'. chr (10 ). chr (9 ). 'boundary = "'. $ thr_boundary. "\" \ n ";
$ This-> multipart. = '--'. $ thr_boundary. "\ n ";
$ This-> multipart. = 'content-Type: text/plain '. "\ n ";
$ This-> multipart. = 'content-Transfer-Encoding: base64'. "\ n ";
$ This-> multipart. = chunk_split (base64_encode ($ this-> html_text). "\ n ";
// Ttj added below
$ This-> multipart. = '--'. $ thr_boundary. "\ n ";
$ This-> multipart. = 'content-Type: text/html'. "\ n ";
$ This-> multipart. = $ this-> html. "\ n ";
$ This-> multipart. = '--'. $ thr_boundary. "-- \ n ";
// Ttj added above
$ This-> multipart. = '--'. $ thr_boundary. "\ n ";
$ This-> multipart. = 'content-Type: text/html'. "\ n ";
$ This-> multipart. = 'content-Transfer-Encoding: base64'. "\ n ";
$ This-> multipart. = chunk_split (base64_encode ($ this-> html). "\ n ";
$ This-> multipart. = '--'. $ thr_boundary. "-- \ n ";
For ($ I = 0; $ I
Html_images); $ I ++ ){
$ This-> multipart. = '--'. $ sec_boundary. "\ n ";
$ This-> build_html_image ($ I );
}
$ This-> multipart. = "--". $ sec_boundary. "-- \ n ";
}
}
/***************************************
** Adds an image to the list of embedded
** Images.
***************************************/
Function add_html_image ($ file, $ name = ', $ c_type = 'application/octet-stream', $ location = '){
$ This-> html_images [] = array ('body' => $ file,
'Name' => $ name,
'C _ type' => $ c_type,
'Location' => $ location,
'CID' => md5 (uniqid (time ())));
}
/***************************************
** Adds a file to the list of attachments.
***************************************/
Function add_attachment ($ file, $ name = ', $ c_type = 'application/octet-stream '){
$ This-> parts [] = array ('body' => $ file,
'Name' => $ name,
'C _ type' => $ c_type );
}
/***************************************
** Builds an embedded image part of
** Html mail.
***************************************/
Function build_html_image ($ I ){
$ This-> multipart. = 'content-Type: '. $ this-> html_images [$ I] ['c _ type'];
If ($ this-> html_images [$ I] ['name']! = ') $ This-> multipart. ='; name = "'. $ this-> html_images [$ I] ['name']." \ "\ n ";
Else $ this-> multipart. = "\ n ";
$ This-> multipart. = 'content-Transfer-Encoding: base64'. "\ n ";
$ This-> multipart. = 'content-Location: '. $ this-> html_images [$ I] ['location']. "\ n ";
$ This-> multipart. = 'content-ID: <'. $ this-> html_images [$ I] ['CID']. "> \ n ";
$ This-> multipart. = chunk_split (base64_encode ($ this-> html_images [$ I] ['body']). "\ n ";
}
/***************************************
** Builds a single part of a multipart
** Message.
***************************************/
Function build_part ($ I ){
$ Message_part = ';
$ Message_part. = 'content-Type: '. $ this-> parts [$ I] ['c _ type'];
If ($ this-> parts [$ I] ['name']! = ')
$ Message_part. = '; name = "'. $ this-> parts [$ I] ['name']." \ "\ n ";
Else
$ Message_part. = "\ n ";
// Determine content encoding.
If ($ this-> parts [$ I] ['c _ type'] = 'text/plain '){
$ Message_part. = 'content-Transfer-Encoding: base64'. "\ n ";
$ Message_part. = chunk_split (base64_encode ($ this-> parts [$ I] ['body']). "\ n ";
} Else {
$ Message_part. = 'content-Transfer-Encoding: base64'. "\ n ";
$ Message_part. = 'content-Disposition: attachment; filename = "'. $ this-> parts [$ I] ['name']." \ "\ n ";
$ Message_part. = chunk_split (base64_encode ($ this-> parts [$ I] ['body']). "\ n ";
}
Return $ message_part;
}
/***************************************
** Builds the multipart message from
** List ($ this-> parts ).
***************************************/
Function build_message (){
$ Boundary = '= _'. md5 (uniqid (time ()));
$ This-> headers. = "MIME-Version: 1.0 \ n ";
$ This-> headers. = "Content-Type: multipart/mixed ;". chr (10 ). chr (9 ). "boundary = \"". $ boundary. "\" \ n ";
$ This-> multipart = ';
// $ This-> multipart. = "This is a MIME encoded message. \ nCreated by html_mime_mail.class. \ nSee http://www.heyes-computing.net/scripts/ for a copy. \ n ";
If (isset ($ this-> do_html) AND $ this-> do_html = 1) $ this-> build_html ($ boundary );
If (isset ($ this-> body) AND $ this-> body! = ') $ This-> parts [] = array ('body' => $ this-> body, 'name' => ', 'c _ type' => 'text/plain ');
For ($ I = (count ($ this-> parts)-1); $ I> = 0; $ I --){
$ This-> multipart. = '--'. $ boundary. "\ n". $ this-> build_part ($ I );
}
$ This-> mime = $ this-> multipart. "--". $ boundary. "-- \ n ";
}
/***************************************
** Sends the mail.
***************************************/
Function send ($ to_name, $ to_addr, $ from_name, $ from_addr, $ subject = ', $ headers = '){
If ($ to_name! = ') $ To =' "'. $ to_name.'" <'. $ to_addr.'> ';
Else $ to = $ to_addr;
If ($ from_name! = ') $ From =' "'. $ from_name.'" <'. $ from_addr.'> ';
Else $ from = $ from_addr;
Mail ($ to, $ subject, $ this-> mime, 'From :'. $ from. "\ n ". $ headers. "\ n ". $ this-> headers );
}
/***************************************
** Use this method to deliver using direct
** Smtp connection. Relies upon Manuel Lemos'
** Smtp mail delivery class available:
** Http://phpclasses.upperdesign.com
**
** Void smtp_send (string * Name * of smtp object,
** String From address,
** Array To addresses,
** String Subject)
***************************************/
Function smtp_send ($ smtp_obj, $ from_addr, $ to_addr, $ subject ){
Global $ smtp_obj;
$ Smtp_obj = $ smtp_obj;
$ This-> headers. = 'from: '. $ from_addr. "\ n ";
$ This-> headers. = 'Subject: '. $ Subject. "\ n ";
If (substr ($ this-> headers,-2) = "\ n") $ this-> headers = substr ($ this-> headers, 0,-2 );
$ This-> headers = explode ("\ n", $ this-> headers );
$ Smtp_obj-> sendmessage ($ from_addr, $ to_addr, $ this-> headers, $ this-> mime );
}
} // End of class.
?>