附件怎么发送 php,php写的发送附件的程序(一)

这段代码展示了如何使用PHP的html_mime_mail类来创建并发送包含文本、HTML内容以及附件的电子邮件。程序首先读取两个文件(background.gif和example.zip),然后将它们作为邮件的嵌入图像和附件。邮件构建完成后,调用send方法进行发送。
摘要由CSDN通过智能技术生成

php写的发送附件的程序(一)推荐查看本文HTML版本

  

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 = '

    Success!

';

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

** 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值