php 发送带pdf附件的email 出现的是一长串字符串 请教怎么解决
程序员文章站
2022-04-25 20:43:03
...
php 发送带pdf附件的email 出现的是一长串字符串 请问如何解决
RT,发出的email附件不是一个pdf档,而变成了一长串字符串,
我的发送email的代码如下:
function mail($mailto, $userid, $data){
global $dsql,$cfg_adminemail,$cfg_webname,$cfg_basehost,$cfg_memberurl;
$mailtitle = $cfg_webname.":通知";
$file=fopen("D:/xampp/htdocs/pdftemp/dsfasdf.pdf","r");
$fileName=$data['oid'].'.pdf';
$mimeType ="application/pdf";
$boundary = "nextpart_".uniqid(""); //分隔符1
$boundary2 = "nextpart2_".uniqid(""); //分隔符2
//email头
$headers = "From: ".$cfg_adminemail."\r\nReply-To: $cfg_adminemail";
$headers .= "Content-type: multipart/mixed; boundary=\"$boundary1\"\r\n";
//读取文件
$read = fread($file, filesize("D:/xampp/htdocs/pdftemp/dsfasdf.pdf"));
//我们用base64方法把它编码
$read = base64_encode($read);
//把这个长字符串切成由每行76个字符组成的小块
$read = chunk_split($read);
//以下是mailbody正文
$mailbody = "--$boundary1----$boundary2
Content-type: text/plain;charset=iso-8859-1;
Content-transfer-encoding: 8bit";
$mailbody .= '致: '.$userid.',
This is mailbody--$boundary2--';
//以下是附件部分
$mailbody .="--$boundary1
Content-type: text/html; name=$fileName
Content-disposition: inline; filename=$fileName
Content-transfer-encoding: 8bit
$read
--$boundary1--";
$status = smail($mailto,$mailtitle,$mailbody,$headers);
setMail($mailto, $mailtitle, $mailbody, $headers, $status);
return $status;
}
RT,发出的email附件不是一个pdf档,而变成了一长串字符串,
我的发送email的代码如下:
function mail($mailto, $userid, $data){
global $dsql,$cfg_adminemail,$cfg_webname,$cfg_basehost,$cfg_memberurl;
$mailtitle = $cfg_webname.":通知";
$file=fopen("D:/xampp/htdocs/pdftemp/dsfasdf.pdf","r");
$fileName=$data['oid'].'.pdf';
$mimeType ="application/pdf";
$boundary = "nextpart_".uniqid(""); //分隔符1
$boundary2 = "nextpart2_".uniqid(""); //分隔符2
//email头
$headers = "From: ".$cfg_adminemail."\r\nReply-To: $cfg_adminemail";
$headers .= "Content-type: multipart/mixed; boundary=\"$boundary1\"\r\n";
//读取文件
$read = fread($file, filesize("D:/xampp/htdocs/pdftemp/dsfasdf.pdf"));
//我们用base64方法把它编码
$read = base64_encode($read);
//把这个长字符串切成由每行76个字符组成的小块
$read = chunk_split($read);
//以下是mailbody正文
$mailbody = "--$boundary1----$boundary2
Content-type: text/plain;charset=iso-8859-1;
Content-transfer-encoding: 8bit";
$mailbody .= '致: '.$userid.',
This is mailbody--$boundary2--';
//以下是附件部分
$mailbody .="--$boundary1
Content-type: text/html; name=$fileName
Content-disposition: inline; filename=$fileName
Content-transfer-encoding: 8bit
$read
--$boundary1--";
$status = smail($mailto,$mailtitle,$mailbody,$headers);
setMail($mailto, $mailtitle, $mailbody, $headers, $status);
return $status;
}
php email pdf
专题推荐
-
独孤九贱-php全栈开发教程
全栈 170W+
主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门
-
玉女心经-web前端开发教程
入门 80W+
主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门
-
天龙八部-实战开发教程
实战 120W+
主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习
- 最新文章
- 热门排行
上一篇: PHP教程 基本语法
下一篇: 在Python中使用正则表达式的方法
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论