-
- var $addr_to;
- var $text_body;
- var $text_encoded;
- var $mime_headers;
- var $mime_boundary = "--==================_846811060==_";
- var $smtp_headers;
-
- function CMailFile($subject,$to,$from,$msg,$filename,$downfilename,$mimetype = "application/octet-stream",$mime_filename = false) {
- $this- >主題=$主題;
- $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);
- }
-
- function Attach_file($filename,$downfilename,$mimetype,$mime_filename) {
- $encoded = $this->encode_file($filename);
- if ($mime_filename) $filename = $mime_filename;
- $out = "--" 。 ”;
- $out = $out 。 “內容傳輸編碼:base64n”;
- $out = $out 。 。 >
- functionencode_file($sourcefile) {
- if (is_read($sourcefile)) {
- $fd = fopen($sourcefile, "r");
- $contents = fread($fd, filesize($sourcefile));
- $encoded = chunk_split(base64_encode($contents));
- fclose($fd);
- }
- 回傳 $encoded;
- }
-
- function sendfile() {
- $headers = $this->smtp_headers . $this->mime_headers;
- $message = $this->text_body 。
- 郵件($this->addr_to,$this->subject,$message,$headers);
- }
-
- function write_body($msgtext) {
- $out = "--" . $this->mime_boundary 。 。 「n」;
- 返回$out;
- }
-
- function write_mimeheaders($filename, $mime_filename) {
- if ($mime_filename) $filename = $mime_filename;
- $out = "MIME 版本: 1.0n";
- $out = $out 。
- $out = $out 。 “內容傳輸編碼:7BITn”;
- $out = $out 。 “X-附件:$檔名;nn”;
- 回傳$out;
- }
-
- function write_smtpheaders($addr_from) {
- $out = "寄件者:$addr_fromn";
- $out = $out 。 “回复:$addr_fromn”;
- $out = $out 。 “X-Mailer:PHP3n”;
- $out = $out 。 」;
- 回傳$out;
- }
- }
-
- /* 實作- 例如:mimetype 為"image/gif"
- $mailfile = new CMailFile($subject,$sendtogif"
- $mailfile = new CMailFile($subject,$sendto ,$replyto,$message,$filename,$mimetype);
- $mailfile->sendfile();
-
- $subject -- 主題
- $sendto -- 收信人地址
- $replyto -- 回覆地址
- $message -- 信件內容
- $filename -- 附件檔案名稱
- $downfilename -- 下載的檔案名稱
- $mimetype -- mime 類型
- */
- ?>
-
-
- 複製程式碼
-
-
2,示範範例 demo.php
-
-
require_once('emailclass.php');
-
- //發送郵件
-
- / /主題
- $subject = "test send email";
-
- //收件者
- $sendto = 'abc@163.com';
-
- //寄件人
- $replyto = 'cdf@163.com';
-
- //內容
- $message = "test send email content";
-
- //
- $ filename = 'test.jpg';
-
- //附件類別
- $mimetype = "image/jpeg";
-
- $mailfile = new CMailFile($subject,$sendto,$ replyto, $message,$filename,$excelname,$mimetype);
- $mailfile->sendfile();
- ?>
複製程式碼
>複製程式碼 >> >> 您可能感興趣的文章:
php socket使用smtp寄送附附件的郵件
Php中IMAP應用舉例(收發郵件、刪除郵件、附件下載)
PHPMailer發送附附件郵件的範例
|
PHPMailer發送郵件中文附件名亂碼的解決方法