分享
 
 
 

php写的发送附件的程序实例

王朝php·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

<?

error_reporting(63);

include('class.html_mime_mail.inc');

/***************************************

** Example of usage.

***************************************/

/***************************************

** Read the file background.gif into

** $backgrnd.

***************************************/

$filename = 'background.gif';

$backgrnd = fread($fp = fopen($filename, 'r'), filesize($filename));

fclose($fp);

/***************************************

** Read the file test.zip into $attachment.

***************************************/

$filename = 'example.zip';

$attachment = fread($fp = fopen($filename, 'r'), filesize($filename));

fclose($fp);

/***************************************

** Create the mail object. Optional headers

** argument. Do not put From: here, this

** will be added when $mail->send

***************************************/

$mail = new html_mime_mail("X-Mailer: Html Mime Mail Class\r\n");

/***************************************

** If sending an html email, then these

** two variables specify the text and

** html versions of the mail. Don't

** have to be named as these are. Just

** make sure the names tie in to the

** $mail->add_html() command further down.

***************************************/

$text = 'This is a test.';

$html = '<HTML><BODY BACKGROUND="background.gif"><FONT FACE="Verdana, Arial" COLOR="#FF0000"> Success!</FONT><P></BODY></HTML>';

/***************************************

** Add the text, html and embedded images.

** Each embedded image has to be added

** using $mail->add_html_image() BEFORE

** calling $mail->add_html(). The name

** of the image should match exactly

** (case-sensitive) to the name in the html.

***************************************/

$mail->add_html_image($backgrnd, 'background.gif', 'image/gif');

$mail->add_html($html, $text);

/***************************************

** If not sending an html email, then

** this is used to set the plain text

** body of the email.

***************************************/

// $mail->body = 'fsss';

/***************************************

** This is used to add an attachment to

** the email.

***************************************/

$mail->add_attachment($attachment, 'example.zip', 'application/octet-stream');

/***************************************

** Builds the message.

***************************************/

$mail->build_message();

/***************************************

** Sends the message. $mail->build_message()

** is seperate to $mail->send so that the

** same email can be sent many times to

** differing recipients simply by putting

** $mail->send() in a loop.

***************************************/

$mail->send('','szw@phpexe.com', 'From Name', 'szw@phpexe.com', 'Subject','');

/***************************************

** Debug stuff. Entirely unnecessary.

***************************************/

echo '<PRE>';

echo $mail->mime;

echo '</PRE>';

?>

<?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,

'name' => $name,

'c_type' => $c_type );

}

/***************************************

** Builds an embedded image part of an

** 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']."\"\r\n";

else $this->multipart .= "\r\n";

$this->multipart.= 'Content-ID: <'.$this->html_images[$i]['cid'].">\r\n";

$this->multipart.= 'Content-Transfer-Encoding: base64'."\r\n\r\n";

$this->multipart.= chunk_split(base64_encode($this->html_images[$i]['body']))."\r\n";

}

[1] [2] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有