I'm using sendgrid to send mails from my app, all is fine until I try and add an attachment (a pdf generated within the page and stored as a variable).
The pdf sends if I use the standard php mail function however I want to add this to my sendgrid mail, I'm using the following code but am not having any luck:
$sendgrid = new SendGrid('SENDGRID_KEY');
$email = new SendGrid\Email();
$email
->addTo('[email protected]')
->addBcc('[email protected]')
->setFrom('[email protected]')
->setSubject('Example')
->setFiles($pdfdoc)
->setHtml($example_html);
$sendgrid->send($email);
echo "you just sent a mail! <br>";
I've tried ->setsetFiles() and ->setAttachment() but neither seems to work and I get the following error message:
[09-Sep-2016 03:55:19 UTC] PHP Fatal error: Uncaught exception 'Guzzle\Common\Exception\InvalidArgumentException' with message 'Unable to open %PDF-1.4 3 0 obj
does anyone have any idea of how to do this?