/ Published in: PHP
Expand |
Embed | Plain Text
<?php # | p11creative mime email class # | $Id: mime.php,v 1.1.1.1 2004/01/21 00:17:16 ryan Exp $ # | define a few MIME types "); class MIME_mail { var $to; var $from; var $subject; var $body; var $headers = ""; var $errstr=""; var $base64_func= ''; # | use default php base64 function var $qp_func = ''; # | leave blank for now var $mailer = ""; # | set to alternate mailer # | private: function MIME_mail($from="", $to="", $subject="", $body="", $headers = "") { $this->to = $to; $this->from = $from; $this->subject = $subject; $this->body = $body; else $headers=$headers[0]; } if ($from) { ]?\b)!i", '', $headers); } $this->mimeparts[] = ""; $this->errstr = ""; return; } # | Attach a 'file' to e-mail message # | Pass a file name to attach. # | This function returns a success/failure code/key of current # | attachment in array (+1). Read attach() below. function fattach($path, $description = "", $contenttype = OCTET, $encoding = BASE64, $disp = '') { $this->errstr = ""; return 0; } if (!$fp) { $this->errstr = "fopen() failed"; return 0; } $contenttype .= "; return $this->attach($data, $description, $contenttype, $encoding, $disp); } # | Attach data provided by user (rather than a file) # | Useful when you want to MIME encode user input # | like HTML. NOTE: This function returns key at which the requested # | data is attached. IT IS CURRENT KEY VALUE + 1!! # | Construct the body with MIME parts function attach($data, $description = "", $contenttype = OCTET, $encoding = BASE64, $disp = '') { $this->errstr = ""; $this->errstr = "No data to be attached"; return 0; } if ($encoding == BIT7) $emsg = $data; elseif ($encoding == QP) $emsg = $$this->qp_func($data); elseif ($encoding == BASE64) { if (!$this->base64_func) else $emsg = $$this->base64_func($data); } if ($contenttype != (HTML || TEXT)) { } # | Check if content-type is text/plain and if charset is not specified append default CHARSET $contenttype .= "; \tcharset=".CHARSET ; $contenttype.CRLF, $encoding.CRLF, ((($description) && (BODY != $description))?"Content-Description: $description".CRLF:""), ($disp?"Content-Disposition: $disp".CRLF:""), CRLF.$emsg.CRLF); BODY == $description? $this->mimeparts[0] = $msg: $this->mimeparts[] = $msg ; } # | Construct mail message header from info already given. # | This is a very important function. It shows how exactly # | the MIME message is constructed. function build_message() { $this->errstr = ""; $msg = ""; # | Attachment list is there. Therefore MIME Message header must have multipart/mixed $c_ver = "MIME-Version: 1.0".CRLF; $c_type = 'Content-Type: multipart/mixed;'.CRLF."\tboundary=\"$boundary\"".CRLF; $c_enc = "Content-Transfer-Encoding: ".BIT7.CRLF; $c_desc = $c_desc?"Content-Description: $c_desc".CRLF:""; $warning = CRLF.WARNING.CRLF.CRLF ; # | Since we are here, it means we do have attachments => body must become an attachment too. $this->attach($this->body, BODY, TEXT, BIT7); } # | Now create the MIME parts of the email! for ($i=0 ; $i < $nparts; $i++) { $msg .= CRLF.'--'.$boundary.CRLF.$this->mimeparts[$i].CRLF; } $msg .= '--'.$boundary.'--'.CRLF; $msg = $c_ver.$c_type.$c_enc.$c_desc.$warning.$msg; else: endif; return $msg; } # | Now Generate the entire Mail Message, header and body et al. function gen_email($force=false) { $this->errstr = ""; $email = ""; $email .= $this->build_message(); $this->email = $email; return $this->email; } # | Printable form function print_mail($force=false) { $this->errstr = ""; $email = $this->gen_email($force); print $email; } # | Send mail via local mailer function send_mail($force=false) { $this->errstr = ""; $email = $this->gen_email($force); $this->errstr = "To Address not specified"; return 0; } $mail_obj = $this->mailer['name']; $mail_method = $this->mailer['method']; $this->errstr = "Invalid object name passed to send_mail()"; return 0; } global $mail_obj; return $ret; } } } ?>
You need to login to post a comment.
