在我的控制器中生成pdf布局,然后将其附加为Pdf并使用自定义文件名。这是代码
$this->load->library('mpdf');
$mpdf = new Mpdf('L', 'A4', 0, 'Trebuchet MS', 6, 6, 9, 9, 3, 3, 'L');
ob_start();
echo $this->generateFoodReport($inspectionId);
$html = ob_get_contents();
ob_end_clean();
$mpdf->WriteHTML(utf8_encode($html));
$content = chunk_split(base64_encode($mpdf->Output('', 'S')));
$filename = "inspection-report.pdf";
$this->load->library('email');
$this->email->set_mailtype("html");
$this->email->set_newline("\r\n");
$this->email->from($fromMail, $fromName);
$this->email->to($mailTo);
$this->email->subject($subject);
$this->email->attach($content):
$this->email->send();
如何使用电子邮件附加文件。
答案 0 :(得分:1)
将普通PDF缓冲区发送到邮件类。
$content = $mpdf->Output('', 'S');
$this->email->attach($content, 'attachment', $filename, 'application/pdf');
答案 1 :(得分:0)
尝试以下代码
$this->load->library('mpdf');
$mpdf = new Mpdf('L', 'A4', 0, 'Trebuchet MS', 6, 6, 9, 9, 3, 3, 'L');
ob_start();
echo $this->generateFoodReport($inspectionId);
$html = ob_get_contents();
ob_end_clean();
$mpdf->WriteHTML(utf8_encode($html));
$content = chunk_split(base64_encode($mpdf->Output('', 'S')));
$filename = "inspection-report.pdf";
$this->load->library('email');
$this->email->set_mailtype("html");
$this->email->set_newline("\r\n");
$this->email->from($fromMail, $fromName);
$this->email->to($mailTo);
$this->email->subject($subject);
$this->email->attach($content, 'attachment', $filename, 'application/pdf');
$this->email->send();