我正在生成dpf并通过电子邮件发送它并且它对我来说很好但我只想附加上传到我的html表单的文件。我正在使用dompdf。
这是我的代码:
$title = $_POST['title'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$target = "uploads/";
$target1 = $target . basename($_FILES['pass_doc']['name']);
//Here we check that $ok was not set to 0 by an error
move_uploaded_file($_FILES['pass_doc']['tmp_name'], $target1);
$pass_doc = $_FILES['pass_doc']['name'];
$dir = dirname(__FILE__);
$pdf_html = "Name: $title $fname";
require_once($dir.'/dompdf/dompdf_config.inc.php');
$dompdf = new DOMPDF(); // Create new instance of dompdf
$dompdf->load_html($pdf_html); // Load the html
$dompdf->render(); // Parse the html, convert to PDF
$pdf_content = $dompdf->output(); // Put contents of pdf into variable for later
// Get the contents of the HTML email into a variable for later
ob_start();
require_once($dir.'/html.php');
$html_message = ob_get_contents();
ob_end_clean();
// Load the SwiftMailer files
require_once($dir.'/swift/swift_required.php');
$mailer = new Swift_Mailer(new Swift_MailTransport()); // Create new instance of SwiftMailer
$message = Swift_Message::newInstance()
->setSubject('Student Inquiry from lsbuk.com') // Message subject
->setTo(array('myemail@example.com')) // Array of people to send to
->setFrom(array('no-reply@example.com' => 'LSBUK')) // From:
->setBody($html_message, 'text/html') // Attach that HTML message from earlier
->attach(Swift_Attachment::newInstance($pdf_content, 'studentadmission.pdf', 'newstudent/pdf')); // Attach the generated PDF from earlier
// Send the email, and show user message
if ($mailer->send($message))
$success = true;
else
$error = true;
只想知道如何附加$ pass_doc?生成的pdf工作正常,并在电子邮件中但不是$ pass_doc
由于
答案 0 :(得分:0)
我已经修改了它,只需将代码放在下面:
->attach(Swift_Attachment::fromPath($pass_doc_path))
无论如何,谢谢