Php 使用Codeigniter在电子邮件中发送pdf而不将其保存在服务器上
我一直在尝试发送带有Php 使用Codeigniter在电子邮件中发送pdf而不将其保存在服务器上,php,codeigniter,email,pdf,Php,Codeigniter,Email,Pdf,我一直在尝试发送带有pdf附件的电子邮件,该附件由codeigniter中的MPDF库生成。从我的观点来看,我已经成功地将我的文件转换为pdf,或者我认为我已经转换了,但我找不到任何方法使用codeigniter中的给定功能将该文件附加到电子邮件 在Codeignator的文档中,attach功能的描述混乱且不完整,这表明: $this->email->attach($buffer,'attachment','report.pdf', "申请表格(pdf); 其中$buffer是字符串repor
pdf
附件的电子邮件,该附件由codeigniter中的MPDF
库生成。从我的观点来看,我已经成功地将我的文件转换为pdf
,或者我认为我已经转换了,但我找不到任何方法使用codeigniter中的给定功能将该文件附加到电子邮件
在Codeignator的文档中,attach
功能的描述混乱且不完整,这表明:
$this->email->attach($buffer,'attachment','report.pdf',
"申请表格(pdf);
其中$buffer
是字符串report.pdf
将是电子邮件附件的文件名
现在我关心的是,我是否可以附加生成的视图,如下所示:
ini_set('memory_limit', '20M');
// load library
$this->load->library('pdf');
$pdf = $this->pdf->load();
// boost the memory limit if it's low ;)
$html = $this->load->view('reports/someReport', array('var' => 123), true);
// render the view into HTML
$pdf->WriteHTML($html);
$this->email->attach($pdf->Output('', 'S'), 'attachment', 'report.pdf', 'application/pdf'); // is this okay or something is wrong here ?
如何通过电子邮件成功附加并发送它首先,您可以将PDF文件保存在项目文件夹中,如
附加
。然后将此pdf位置设置为电子邮件附件。像贝娄一样:
<?php
ini_set('memory_limit', '20M');
// load library
$this->load->library('pdf');
$pdf = $this->pdf->load();
// boost the memory limit if it's low ;)
$html = $this->load->view('reports/someReport', array('var' => 123), true);
// render the view into HTML
$pdfFilePath = FCPATH . "attach/pdf_name.pdf";
$pdf->WriteHTML($html);
$pdf->Output($pdfFilePath, "F");
$result = $this->email
->from('example@test.com', 'From name')
->to('test@test.com')
->subject($subject)
->message($body)
->attach($pdfFilePath)
->send();
$this->email->clear($pdfFilePath);
if($result) {
echo "Send";
unlink($pdfFilePath); //for delete generated pdf file.
}
?>
以上代码的问题是每次发送电子邮件时都会保存文件,是否有任何方法可以绕过此问题?请通知我。现在用pdf发送附件?让我测试一下。我收到了这个错误mPDF错误:无法创建输出文件:/home/myusername/public\u html/app\u rest/attach/pdf\u name.pdf
,这里app\u rest
文件夹是CodeIgnitor的根目录在app\u rest/attach
文件夹中成功创建pdf文件吗?