Reputation: 1768
I am dynamically generating pdf files using dompdf and attaching those to email and sending. But in mail always Im getting the attachment as 0 byte. I'am creating the files under cake's tmp folder and it is getting created successfully. Im using cakephp 2.x and sending mail using CakeEmail. dompdf folders are in plugin folder. I have given necessary permission to lib/fonts directory. The file is not sending as attachment immediately after the creation. Whether there will be any kind of locking/delay while using dompdf that is cakeemail could not able to get the contents of the file (but file exists) ?
App::uses('CakePdf', 'CakePdf.Pdf');
$CakePdf = new CakePdf();
$orderDetails = array('1' => 'myproduct');
$CakePdf->viewVars(compact('orderDetails'));
$CakePdf->template('view_ticket_pdf', 'default');
$filename = TMP . $data['Billing']['order_id'] . '.pdf';
$pdf = $CakePdf->output();
$CakePdf->write( $filename);
$email = new CakeEmail('smtp');
$desc = $email->template('order_mail');
$email->emailFormat('html');
$email->from(array(ADMIN_EMAIL => 'Admin'));
$email->to('[email protected]');
$email->attachments(array($filename));
$email->subject('Your order');
$content = $email->send();
Im getting error as fread(): Length parameter must be greater than 0 in CakeEmail. Instead of pdf, if I create a sample text file, it is attaching and size will be greater than 0. I am using github.com/ceeram/CakePdf plugin for pdf creation.
Upvotes: 0
Views: 1388
Reputation: 724
Same problem here ($Email->attachments() does not attach file). It is not a locking issue by the way. If you write your PDF to a database you can do an ugly workaround. Have a look here: https://stackoverflow.com/a/17744761/1145597
Upvotes: 0