我一直在尝试从我的视图发送带有pdf
MPDF
库生成的PDF
附件的电子邮件,我已成功将我的文件转换为attach
或我认为我做了,但我无法找到任何方法使用CodeIgniter中的给定功能将该文件附加到电子邮件。
在CodeIgnitor的文档中,对$buffer
函数的一个令人困惑和不完整的描述暗示了这一点:
$ this-> email-> attach($ buffer,'attachment','report.pdf', '应用程序/ PDF');
其中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 ?
将是fileName,其中附带电子邮件,
现在我关注的是我可以附加我生成的视图:
if &var. not in ('quarter' 'period' 'year') then do;
proc sort data=test_&var.;
by descending column1;
run;
end;
如何通过电子邮件成功附加并发送
答案 0 :(得分:1)
首先,您可以将PDF文件保存在项目文件夹中,如attach
。然后这个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.
}
?>