使用PHPMailer发送FPDF文档; [英] Send FPDF document with PHPMailer;

查看:200
本文介绍了使用PHPMailer发送FPDF文档;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用FPDF生成PDF,然后将其发送到带有PHPMailer的电子邮件中。我知道PHPMailer功能正在运行,我可以创建pdf。但是,当我尝试将pdf下载到服务器时,输出($ pdf,F),我得到错误:

I am currently trying to generate a pdf with FPDF and then send it in an email with PHPMailer. I know that the PHPMailer functionality is working, and I can create the pdf. But when i try to download the pdf to the server first, output($pdf,"F"), I get the error:


警告(2):fopen(/temp-file.pdf):无法打开流:权限被拒绝[APP / Vendor / fpdf / fpdf.php,行1025] FPDF错误:无法创建输出文件:/ temp-file。 pdf

Warning (2): fopen(/temp-file.pdf): failed to open stream: Permission denied [APP/Vendor/fpdf/fpdf.php, line 1025]FPDF error: Unable to create output file: /temp-file.pdf

pdf创建时间很长,所以我只会告诉你我试图忽略它。

The pdf creation is very long, so i will just show you me trying to ouptut it.

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");
                    }

有人有我的解决方案吗?
谢谢!

Does anyone have a solution for me? Thank you!

推荐答案

你只需要修改你的权限。如果FPDF无法写入文件,那么PHPMailer就没有什么可以发送的,所以当然不行。

You just need to fix your permissions. If FPDF can't write the file, then there's nothing for PHPMailer to send, so of course it won't work.

或者你可以渲染一个字符串并附加这样就不需要写一个文件:

Alternatively you can render to a string and attach that instead - this way it doesn't need to write a file:

$pdfdoc = $pdf->Output('', 'S');
...
$mail->addStringAttachment($pdfdoc, 'my-doc.pdf');

这篇关于使用PHPMailer发送FPDF文档;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆