emailclass.php
[PHP] View plaincopyprint?
01.<?
02.class Cmailfile {
03.
var $subject;
-Var $addr _to;
_body var $text;
_encoded var $text;
_headers var $mime;
var $mime _boundary = "--==================_846811060==_";
var $smtp _headers;
11.
function Cmailfile ($subject, $to, $from, $msg, $filename, $downfilename, $mimetype = "Application/octet-stream", $ Mime_filename = False) {
$this->subject = $subject;
$this->addr_to = $to;
$this->smtp_headers = $this->write_smtpheaders ($from);
$this->text_body = $this->write_body ($msg);
$this->text_encoded = $this->attach_file ($filename, $downfilename, $mimetype, $mime _filename);
$this->mime_headers = $this->write_mimeheaders ($filename, $mime _filename);
19.}
20.
function Attach_file ($filename, $downfilename, $mimetype, $mime _filename) {
$encoded = $this->encode_file ($filename);
if ($mime _filename) $filename = $mime _filename;
$out = "--". $this->mime_boundary. "\ n";
$out = $out. "Content-type:". $mimetype. "; Name=\ "$filename \"; \ n ";
$out = $out. "Content-transfer-encoding:base64\n";
$out = $out. "Content-disposition:attachment; filename=\ "$downfilename \ \ n";
$out = $out. $encoded. "\ n";
$out = $out. "--" . $this->mime_boundary. "--" . "\ n";
return $out;
31.}
32.
function Encode_file ($sourcefile) {
if (is_readable ($sourcefile)) {
$FD = fopen ($sourcefile, "R");
$contents = Fread ($FD, FileSize ($sourcefile));
$encoded = Chunk_split (Base64_encode ($contents));
Fclose ($FD);
39.}
return $encoded;
41.}
42.
function Sendfile () {
$headers = $this->smtp_headers. $this->mime_headers;
$message = $this->text_body. $this->text_encoded;
Mail ($this->addr_to, $this->subject, $message, $headers);
47.}
48.
function Write_body ($msgtext) {
$out = "--". $this->mime_boundary. "\ n";
$out = $out. "Content-type:text/plain; Charset=\ "Us-ascii\" "\ n";
$out = $out. $msgtext. "\ n";
return $out;
54.}
55.
function Write_mimeheaders ($filename, $mime _filename) {
if ($mime _filename) $filename = $mime _filename;
$out = "mime-version:1.0\n";
$out = $out. "Content-type:multipart/mixed;";
$out = $out. "Boundary=\" $this->mime_boundary\ "\ n";
$out = $out. "Content-transfer-encoding:7bit\n";
$out = $out. "x-attachments: $filename; \ n";
A. return $out;
64.}
65.
function write_smtpheaders ($addr _from) {
$out = "From: $addr _from\n";
$out = $out. "Reply-to: $addr _from\n";
$out = $out. "X-mailer:php3\n";
$out = $out. "X-sender: $addr _from\n";
return $out;
72.}
73.}
74.
75./* Usage-for example: MimeType as "Image/gif"
$mailfile = new Cmailfile ($subject, $sendto, $replyto, $message, $filename, $mimetype);
$mailfile->sendfile ();
78.
$subject--Themes
$sendto--The address of the addressee
$replyto--Reply address
$message--Letter contents
$filename--Attachment file name
$downfilename--The name of the download
$mimetype--MIME type
86.*/
87.?>
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/PHP/