php mail邮件发送带附件功能
时间:2014-06-09 16:40来源: 作者: 点击:
次
$pdfname = test.pdf ; $email = test@test.com ; $text = 您好,附件中是您需要的pdf文件。请点击下载。brahref=http://www.vcphp.comwww.vcphp.com/a ;//文本内容 $text = base64_encode ( $text ); //用base64方法把它编码 $text = c
- $pdfname="test.pdf";
- $email="test@test.com";
- $text = "您好,附件中是您需要的pdf文件。请点击下载。<br><a href=http://www.vcphp.com>www.vcphp.com</a>"; //文本内容
- $text = base64_encode($text);
- $text = chunk_split($text);
- $subject = $pdfname;
- $from = "admin@vcphp.com";
- $to = $email;
-
-
- $boundary = "nextpart_".uniqid("");
- $boundary2 = "nextpart_".uniqid("");
- $headers = "to: $torn";
- $headers .= "from: $fromrn";
- $headers .="mime-version: 1.0rn";
- $headers .= "content-type: multipart/mixed;
- boundary="----=_$boundary"rn";
- $read=file_get_contents($pdfname);
- $read = base64_encode($read);
- $read = chunk_split($read);
-
- $body = "this is a multi-part message in mime format.
- ------=_$boundary
- content-type: multipart/alternative;
- boundary="----=_$boundary2";
- ------=_$boundary2
- content-type: text/html;
- charset="gbk"
- content-transfer-encoding: base64
- $text
- ------=_$boundary2--
- ------=_$boundary
- content-type: application/octet-stream;
- charset="gbk";
- name="$pdfname"
- content-disposition: attachment; filename="$pdfname"
- content-transfer-encoding: base64
- $read
- -------=_$boundary--";
- if(mail($to, $subject,$body,$headers))
- echo "您需要的pdf文件(".$pdfname.")已经发往您的邮箱:".$to."。<br>请查收。";
- else
- echo "抱歉,发送失败了。<br>";
(责任编辑:admin) |
------分隔线----------------------------