使用PHPMailer发送已完成的PDF而不保存

时间:2013-02-19 14:57:31

标签: php pdf phpmailer

我是php新手,在构建页面时一直在学习。我目前的任务是能够在浏览器中打开PDF,填写表单,并在单击表单底部的按钮时提交表单。

我们希望在不必将副本保存到服务器的情况下发送完整的表单。虽然有两个形式周期并不可怕。

我目前能够发送电子邮件,但脚本只发送空白文档。

<?php

require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();  // telling the class to use SMTP
$mail->Host     = "xxx.xxx.xxx"; // SMTP server

$mail->From     = "xxx@xxx.xxx";
$mail->AddAddress("xxx@xxx.xxx");

$mail->Subject  = "Attachment Test";
$mail->Body     = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
$mail->AddAttachment('tshirtorderform.pdf');

if(!$mail->Send()) {
  echo 'Message was not sent.';
  echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
  echo 'Message has been sent.';
}
?>

我意识到我正在告诉它要检索空白文件,但是我对如何附上完整的表格感到空虚。

感谢。

2 个答案:

答案 0 :(得分:2)

PHPmailer中有一个半未记录的AddStringAttachment()方法,它允许您直接从字符串附加,而不需要实际的磁盘文件:

http://phpmailer.worxware.com/index.php?pg=tutorial

搜索&#34;字符串附件&#34;。打败我为什么他们不在方法文档中列出。

答案 1 :(得分:0)

我也推荐了AddStringAttachment()方法,但首先你需要使用TCPDF来创建PDF的主体。

我在这个主题中给出了一些提示:AddStringAttachment with PDF in PHPMailer not work

相关问题