php mail邮件发送带附件功能
- $pdfname="test.pdf";
- $email="test@test.com";
- $text = "您好,附件中是您需要的pdf文件。请点击下载。<br><a href=http://www.phpfensi.com>www.phpfensi.com</a>"; //文本内容
- $text = base64_encode($text);
- $text = chunk_split($text);
- $subject = $pdfname;
- $from = "admin@phpfensi.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>";
|