如何通过dompdf附加生成的pdf并将其邮寄到phpmailer中?

问题描述 投票:0回答:5

我正在使用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保存在硬盘驱动器上。

php phpmailer dompdf
5个回答
2
投票

磁盘上没有保存文件:

$pdfString = $dompdf->output();
$mail->addStringAttachment($pdfString, 'name file.pdf');

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()); 

然后附上邮件。


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("[email protected]");    
$m->AddReplyTo("[email protected]");
$m->AddAddress("[email protected]");
$m->Subject( "Connecting Authors Booking Confirmation" );
$m->MsgHTML( "HellonnPlease find attached ..." ); // set the body
$m->AddAttachment( $filename ) ;
$m->Send(); // send the mail
exit();

0
投票

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

$pdf = $dompdf->output();

代替

$pdf = $dompdf->stream('name');

0
投票

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

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

它为我工作。

非常感谢

© www.soinside.com 2019 - 2024. All rights reserved.