I’m using CakePHP 2, CakeEmail and the CakePDF plugin
I’m trying to generate a PDF based on a view and attach it to an email. I’ve read the read me file but am still none the wiser. Do I have to actually create the file on the server?
This is my code so far (email gets sent but no PDF).
// Build PDF as attachment
$CakePdf = new CakePdf();
$CakePdf->template('email_view', 'default');
//get the pdf string returned
$pdf = $CakePdf->output();
// SMTP Options
$this->Email->smtpOptions = array(
// Only to be used internally
'port'=>'25',
'timeout'=>'30',
'host' => '111.111.111.111',
'username'=>'',
'password'=>''
);
$this->Email->template = 'newExpenseClaim';
$this->Email->from = 'Expense Tracker <james@test.com>';
$this->Email->to = 'james@test.com';
$this->Email->subject = 'New Expense Claim Submitted - Please Review';
$this->Email->sendAs = 'both';
$this->Email->delivery = 'smtp';
$this->Email->attachments = $pdf;
// Set username & url in email
$this->set('user', $fu['User']['name']);
$this->set('ms', $ms);
$this->Email->send();
$this->set('smtp_errors', $this->Email->smtpError);
Here is the read me from github:
https://github.com/ceeram/CakePdf
Any help would be gratefully received!
I eventually got this to work, heres what I did:
Basically, I merged all the data I needed to pass to the PDF view into one array then passed it using viewVars().
Hope this helps someone!