I am developing an application in cakephp in which i need to generate a pdf and send it as an email attachment. I have been able to create a pdf view using dompdf but I dont know how to save it as a file and send it as an attachment in email. Please tell me how to achieve this.
Asked
Active
Viewed 1.2k times
0
-
possible duplicate of [Generate pdf with dompdf and send it as an attachment in email using cakephp](http://stackoverflow.com/questions/22111594/generate-pdf-with-dompdf-and-send-it-as-an-attachment-in-email-using-cakephp) – mark Mar 01 '14 at 12:45
1 Answers
9
You can find how to save a file here: 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);
Sending email is very straight forward with CakeEmailL. Take a look here: 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');
-
Thank you for your reply sir. This answer helped me a lot in resolving my issue. – Chirag Agarwal Mar 05 '14 at 04:19