繁体   English   中英

如何使用PHP生成多个PDF并通过电子邮件附件发送?

[英]How to generate more than one PDF and send through email attachment using PHP?

如何生成多个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的解决方案。

尝试使用“ 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.

参见http://www.fpdf.org/en/doc/output.htm

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM