我目前正在尝试使用FPDF生成pdf,然后使用PHPMailer将其发送到电子邮件中 . 我知道PHPMailer功能正常,我可以创建pdf . 但是当我尝试首先将pdf下载到服务器,输出($ pdf,“F”)时,我收到错误:
警告(2):fopen(/temp-file.pdf):无法打开流:权限被拒绝[APP / Vendor / fpdf / fpdf.php,第1025行] FPDF错误:无法创建输出文件:/ temp-file .PDF
pdf创作很长,所以我只会告诉你我试图把它拿出来 .
FPDF
$pdfoutputfile = 'temp-folder/temp-file.pdf';
$pdfdoc = $pdf->Output($pdfoutputfile, 'F');
PHPMailer
$mail = new phpmailer;
$mail->SetFrom("info@company.com","Company");
$mail->AddAddress($to);
$mail->Subject = "Invoice $id";
$body .= "This is an automatically generated message from Company \n";
$mail->Body = $body;
$mail->AddAttachment($pdfoutputfile, 'my-doc.pdf');
if(!$mail->Send()) {
$this->Session->setFlash("Invoice was not sent");
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
$this->Session->setFlash("Invoice was sent");
}
有没有人有我的解决方案?谢谢!
2 回答
您只需要修复您的权限 . 如果FPDF无法写入文件,那么PHPMailer就没有任何内容可以发送,所以当然它不起作用 .
或者,您可以渲染为字符串并将其附加 - 这样就不需要编写文件:
如果您需要保存文件并发送,请使用此功能 .
照顾文件位置 .