我正在开发cakephp中的应用程序,我需要生成一个pdf并将其作为电子邮件附件发送。我已经能够使用dompdf创建一个pdf视图,但我不知道如何将其保存为文件并将其作为附件发送到电子邮件中。请告诉我如何实现这一目标。
答案 0 :(得分:7)
您可以在此处找到如何保存文件:how to save DOMPDF generated content to file?
$html =
'<html><body>'.
'<p>Put your html here, or generate it with your favourite '.
'templating system.</p>'.
'</body></html>';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$output = $dompdf->output();
file_put_contents('Brochure.pdf', $output);
使用CakeEmailL发送电子邮件非常简单。看看这里: http://book.cakephp.org/2.0/en/core-utility-libraries/email.html#sending-attachments
$Email = new CakeEmail();
$Email->from(array('me@example.com' => 'My Site'));
$Email->to('you@example.com');
$Email->subject('About');
$Email->attachments('/full/file/path/Brochure.pdf');
$Email->send('My message');