0

我正在使用 dompdf 生成 pdf,我需要将其附加到 phpmailer 并邮寄。帮助将不胜感激。

<?php
require_once("../../dompdf/dompdf_config.inc.php");

$templateFile = 'prog_report.php';
$content = file_get_contents($templateFile);
$dompdf = new DOMPDF();
$dompdf->load_html($content);

$dompdf->render();
$dompdf->stream("sample.pdf");

?>

这是phpmailer附件模块..

$mail->AddAttachment("images/phpmailer.gif");

我想在此处附上生成的 pdf,并且不应将 pdf 保存在硬盘驱动器上。

4

5 回答 5

3

磁盘上没有保存文件:

$pdfString = $dompdf->output();
$mail->addStringAttachment($pdfString, 'name file.pdf');
于 2018-03-02T15:14:49.843 回答
0

我查看了 DomPDF 的 wiki http://code.google.com/p/dompdf/wiki/FAQ上的常见问题解答

$pdf = $dompdf->output();

代替

$pdf = $dompdf->stream('name');
于 2013-02-06T12:53:24.203 回答
0

首先在您的服务器中创建pdf文件

为什么不交换它们,首先将pdf创建为文件,然后将创建的文件流回?

$file_to_save = '/home/stsnew/public_html/pdf/file.pdf';
//save the pdf file on the server
file_put_contents($file_to_save, $dompdf->output()); 

然后附上邮件。

于 2012-11-03T13:01:48.590 回答
0

我只是使用下面的代码自己修复了它:

->attach(Swift_Attachment::fromPath($pass_doc_path))

它为我工作。

非常感谢

于 2015-01-14T18:22:47.990 回答
0

嗨,伙计,我使用了 fpdf 库和 php 邮件程序,它的工作原理就像魅力一样,试试这个。

require('fpdf.php');
$filename="bookingconfirmation.pdf";
//rest of pdf code here

$pdf->Output($filename);

include "libMail/class.phpmailer.php";
$m= new Mail; // create the mail
$m->IsSMTP(); // telling the class to use SMTP
$m->Host = "mail.connectingauthors.com"; // SMTP server
$m->SetFrom("susan@connectingauthors.com");    
$m->AddReplyTo("pixelart@optonline.net");
$m->AddAddress("pixelart@optonline.net");
$m->Subject( "Connecting Authors Booking Confirmation" );
$m->MsgHTML( "HellonnPlease find attached ..." ); // set the body
$m->AddAttachment( $filename ) ;
$m->Send(); // send the mail
exit();
于 2012-11-07T12:09:01.567 回答