栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

html2canvas和jsPDF:将生成的pdf作为电子邮件附件发送

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

html2canvas和jsPDF:将生成的pdf作为电子邮件附件发送

请检查

PHP
代码-

function MailWithAttachment($to, $subject, $message, $senderMail, $senderName, $files){    $from = $senderName." <".$senderMail.">";     $headers = "From: $from";    // boundary     $semi_rand = md5(time());     $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";    // headers for attachment     $headers .= "nMIME-Version: 1.0n" . "Content-Type: multipart/mixed;n" . " boundary="{$mime_boundary}"";    // multipart boundary     $message = "--{$mime_boundary}n" . "Content-Type: text/html; charset="UTF-8"n" .    "Content-Transfer-Encoding: 7bitnn" . $message . "nn";    // preparing attachments    if(count($files) > 0){        for($i=0;$i<count($files);$i++){ if(is_file($files[$i])){     $message .= "--{$mime_boundary}n";     $fp =    @fopen($files[$i],"rb");     $data =  @fread($fp,filesize($files[$i]));     @fclose($fp);     $data = chunk_split(base64_enpre($data));     $message .= "Content-Type: application/octet-stream; name="".basename($files[$i]).""n" .      "Content-Description: ".basename($files[$i])."n" .     "Content-Disposition: attachment;n" . " filename="".basename($files[$i]).""; size=".filesize($files[$i]).";n" .      "Content-Transfer-Encoding: base64nn" . $data . "nn"; }        }    }    $message .= "--{$mime_boundary}--";    $returnpath = "-f" . $senderMail;    //send email    $mail = @mail($to, $subject, $message, $headers, $returnpath);    //function return true, if email sent, otherwise return fasle    if($mail){ return TRUE; } else { return FALSE; }}if(!empty($_POST['data'])){    //email variables    $to = 'to-email@email.com';    $from = 'from-email@email.com';    $from_name = 'PDF FIle';    //attachment files path array    $file = base64_depre($_POST['data']);    $subject = 'PHP Email with attachment';     $html_content = '<h1>PHP Email with attachment</h1>';    //call MailWithAttachment() function and pass the required arguments    $send_email = MailWithAttachment($to,$subject,$html_content,$from,$from_name,$file);    //print message after email sent    echo $send_email?"<h1> Mail Sent</h1>":"<h1> Mail not SEND</h1>";} else {    echo "No Data Found";}

我希望它对您有用:)



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/377928.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号