如何生成多个pdf并通过电子邮件附件发送?
我正在使用fpdf php库生成pdf,并希望通过电子邮件发送多个pdf附件。所以我尝试过,
<?php
require('fpdf.php');
// Generate first One.
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output('.assets/temp/download1.pdf','f');
$file1='.assets/temp/download1.pdf';
// Generate Second PDF.
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output('.assets/temp/download2.pdf','f');
$file2='.assets/temp/download2.pdf';
// use phpmailer to send email.
// load attachments and messages.
// send
// unset files.
?>
这将产生错误消息:FPDF错误:文档已关闭。因为我无法在没有关闭文档的情况下加载两次。因此,请向我询问通过附件发送多个pdf的解决方案。
答案 0 :(得分:0)
尝试使用“ S”参数代替“ F”
$pdf1 = new FPDF();
$pdf1->AddPage();
$pdf1->SetFont('Arial', 'B', 16);
$pdf1->Cell(40, 10, 'Hello World1!');
$file1 = ".assets/temp/download1.pdf";
$pdf1content = $pdf1->Output('S');
file_put_contents($file1, $pdf1content);
$pdf2 = new FPDF();
$pdf2->AddPage();
$pdf2->SetFont('Arial', 'B', 16);
$pdf2->Cell(40, 10, 'Hello World2!');
/**/
$file2 = ".assets/temp/download2.pdf";
$pdf2content = $pdf2->Output('S');
file_put_contents($file2, $pdf2content);
// use phpmailer to send email.
// load attachments and messages.
// send unset files.