Question

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.

Was it helpful?

Solution

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');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top