php 发邮件附件pdf,php – 使用TCPDF发送电子邮件附件 | 码农网
我有一个简单的课程申请表,填写完成后,会向申请人发送一封电子邮件,并附上他选择作为pdf附件的课程的费用报价.
我正在使用TCPDF并使用会话变量将数据从表单传递到库.内容采用 html 格式.
生成PDF并根据需要作为附件发送.问题是它是空白的..只有页眉和页脚在文档中.在 linux 中尤其如此.在Windows中,pdf文档在下载时按预期生成.但是,在下载文档之前单击“视图”时,只显示页眉和页脚.
这是我的代码.请有人帮忙.谢谢.
session_start();
require_once('../config/lang/eng.php');
require_once('../tcpdf.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Josiah Njuki');
$pdf->SetTitle('Quotation Request');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, '', PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// set default font subsetting mode
$pdf->setFontSubsetting(true);
// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
$pdf->SetFont('dejavusans', '', 14, '', true);
// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage();
// Set some content to print
$html = '' . $_SESSION['content'] . '';
$html .= <<
EOD;
// Print text using writeHTMLCell()
$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
// ---------------------------------------------------------
// Close and output PDF document
// This method has several options, check the source code documentation for more information.
//$pdf->Output('example_001.pdf', 'I');
$doc = $pdf->Output('quotation.pdf', 'S');
//define the receiver of the email
$name = "Name goes here";
$email = "jnjuki103@gmail.com";
$to = "$name ";
$from = "John-Smith ";
$subject = "Here is your attachment";
$fileatt = $pdf->Output('quotation.pdf', 'S');
//$fileatt = "./test.pdf";
$fileatttype = "application/pdf";
$fileattname = "newname.pdf";
$headers = "From: $from";
$file = fopen($fileatt, 'rb');
$data = fread($file, filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n" .
"-{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message .= "\n\n";
$data = chunk_split(base64_encode($data));
$message .= "–{$mime_boundary}\n" .
"Content-Type: {$fileatttype};\n" .
" name=\"{$fileattname}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileattname}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"-{$mime_boundary}-\n";
if (mail($to, $subject, $message, $headers)) {
echo "The email was sent.";
} else {
echo "There was an error sending the mail.";
}
//============================================================+
// END OF FILE
//============================================================+
php 发邮件附件pdf,php – 使用TCPDF发送电子邮件附件 | 码农网相关推荐
- wordpress发邮件_如何修复WordPress不发送电子邮件的问题
wordpress发邮件 One of the most commonly asked questions on WPBeginner is how to fix WordPress not send ...
- 在Linux命令行发送电子邮件附件的两种方法
需 求 本文使用Centos7操作系统. 需要有一个工作正常的邮件系统.本文将不介绍如何配置邮件服务器. 1.使用mail命令 安装mailx安装包 [root@localhost ~]# yum - ...
- php 发邮件附件,php发送电子邮件附件
如何发送电子邮件与简历附件, 我从这个地方采取片段Click here 在这个网站上,片段工作正常, 即使我收到邮件,但附件不起作用,与0kb不同的是 大小文件,该片段中的问题是什么, functio ...
- sendgrid java_java – SendGrid电子邮件API,发送电子邮件附件
我使用sendgrid发送电子邮件,使用以下代码工作正常 但它没有附件. package sendgrid; import com.sendgrid.Content; import com.sendg ...
- (邮件/用户)代理协议简介Socket程序发送电子邮件
目录 邮件收发 基本流程 具体过程 协议简介 SMTP POP3 IMAP MIME 在.NET中如何实现 常用的邮件服务器地址: 126邮箱 163邮箱 yahoo邮箱 Sohu邮箱 Gmail邮箱 ...
- nodemailer 附件_如何使用Nodemailer发送带有附件的电子邮件。 Node.js
nodemailer 附件 In the previous article, "How to send emails using Nodemailer?", we discusse ...
- java实现notes发邮件_VBA通过Lotus Notes 6.5与附件发送电子邮件
我有很大的问题 . 我有宏通过Lotus Notes 6.5从Excel发送多封电子邮件 我宏的代码是: Public Function SendNotesMail() 'This public su ...
- python自动发邮件富文本_使用outlook2003发送富文本格式电子邮件
我正在尝试使用Outlook 2003发送RTF格式的电子邮件. 下面的代码会将RTF HTML源代码转储到邮件正文中.在 我该怎么做才能解决这个问题,并使Outlook显示格式化数据而不是源HTML ...
- python发邮件包含表格,在Python中在电子邮件正文中包含Excel表
这样做可能会解决您的问题:import openpyxl from openpyxl import load_workbook workbook = load_workbook(f) workshee ...
最新文章
- java接口与类相同不同_浅谈java的接口和C++虚类的相同和不同之处
- log4j(四)——如何控制不同风格的日志信息的输出?
- 数字锁相环的matlab仿真
- 关于java的public,private,protect,以及默认权限的理解
- 二元函数泰勒公式例题_高等数学期末总复习 DAY 5. 罗尔定理证明题 拉格朗日、柯西中值定理 泰勒公式及麦克劳林公式...
- 谋而后动:解读数仓计划生成中行数估算和路径生成的奥秘
- linux下面的智能解压脚本smart解压
- 410. 分割数组的最大值
- Git(3):git clone远程GitHub仓库代码出现“Permission Denied (publickey)”问题
- 安卓手机无损把mp4视频格式转换成mp3音频格式的方法
- 【TA-霜狼_may-《百人计划》】图形3.4 延迟渲染管线介绍
- 在有滚动条的容器中指定(显示)滚动到某一子元素位置
- android 实现区域截图
- 岁月温柔-9 妈妈吃人参果的后遗症
- [OOD设计] - Black Jack Game (21点)
- 高防服务器单机防御是什么意思?服务器防御100G是什么意思?
- centos 7 dnf命令的安装
- 一台计算机只能注册一台sql,局域网中的一台电脑为啥连接不到另一台电脑中的SQL远程数据库...
- pip安装pytorch和torchvision
- USB HID键盘实现全键无冲解析
热门文章
- 在现有的python环境下创建另一个python版本【亲测有效】
- JAVA实验报告九异常处理_JAVA实验报告_Java异常处理
- 不安装oracle客户端如何用plsql连接oracle
- CSS 布局实例系列(四)如何实现容器中每一行的子容器数量随着浏览器宽度的变化而变化?...
- NOIP201307货车运输
- 使用C语言进行面向对象的开发--GObject入门[5]
- 线程同步(互斥锁、条件、读写锁、信号量)
- 用户id可以出现在url中吗_下载Google Drive中的文件
- 企业非法集资风险预测_2020CCF--企业非法集资风险预测83.35baseline
- java项目皮肤包_java swing项目皮肤包+使用方法说明