PHP教程.应用实例--9

时间:2010-01-07 16:55:39   来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:>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 ...
  正文:

 PHP写的发送附件的程序(二)
<?php
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 with
** 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<count($this->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(!is_array($this->html_images)){
$this->multipart.= '--'.$orig_boundary."/r/n";
$this->multipart.= 'Content-Type: multipart/alternative; boundary="'.$sec_boundary."/"/r/n/r/n/r/n";

$this->multipart.= '--'.$sec_boundary."/r/n";
$this->multipart.= 'Content-Type: text/plain'."/r/n";
$this->multipart.= 'Content-Transfer-Encoding: 7bit'."/r/n/r/n";
$this->multipart.= $this->html_text."/r/n/r/n";

$this->multipart.= '--'.$sec_boundary."/r/n";
$this->multipart.= 'Content-Type: text/html'."/r/n";
$this->multipart.= 'Content-Transfer-Encoding: 7bit'."/r/n/r/n";
$this->multipart.= $this->html."/r/n/r/n";
$this->multipart.= '--'.$sec_boundary."--/r/n/r/n";
}else{
$this->multipart.= '--'.$orig_boundary."/r/n";
$this->multipart.= 'Content-Type: multipart/related; boundary="'.$sec_boundary."/"/r/n/r/n/r/n";

$this->multipart.= '--'.$sec_boundary."/r/n";
$this->multipart.= 'Content-Type: multipart/alternative; boundary="'.$thr_boundary."/"/r/n/r/n/r/n";

$this->multipart.= '--'.$thr_boundary."/r/n";
$this->multipart.= 'Content-Type: text/plain'."/r/n";
$this->multipart.= 'Content-Transfer-Encoding: 7bit'."/r/n/r/n";
$this->multipart.= $this->html_text."/r/n/r/n";

$this->multipart.= '--'.$thr_boundary."/r/n";
$this->multipart.= 'Content-Type: text/html'."/r/n";
$this->multipart.= 'Content-Transfer-Encoding: 7bit'."/r/n/r/n";
$this->multipart.= $this->html."/r/n/r/n";
$this->multipart.= '--'.$thr_boundary."--/r/n/r/n";

for($i=0; $i<count($this->html_images); $i++){
$this->multipart.= '--'.$sec_boundary."/r/n";
$this->build_html_image($i);
}

$this->multipart.= "--".$sec_boundary."--/r/n/r/n";
}
}
/***************************************
** Adds an image to the list of embedded
** images.
***************************************/
function add_html_image($file, $name = '', $c_type='application/octet-stream'){
$this->html_images[] = array( 'body' => $file,
'name' => $name,
'c_type' => $c_type,
'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,
来源:http://www.002pc.com/master/College/Programming/PHP/11577.html

收藏到:

关于《PHP教程.应用实例--9》文章的评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面

随机文章

    SQL Error: select * from ***_ecms_article where classid='86' and checked=1 order by rand() limit 10

顶出来的热门

    SQL Error: select * from ***_ecms_article where classid='86' and checked=1 order by diggtop desc,id desc limit 10
站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td