Sendgrid附件 - pdf php

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('example@mail.com')
        ->addBcc('example@mail.com')
        ->setFrom('example@mail.com')
        ->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?

`#Solved with using web api v2 Curl version like this

$fileName = 'filename.pdf';
$image_data = file_get_contents('gs://my-bucket/filename.pdf');

#sending part

$params = array(
'api_user'  => $user,
'api_key'   => $pass,
'x-smtpapi' => json_encode($json_string),
'to'        => 'email@yourdomain.com',
'subject'   => 'your subject',
'html'      => 'testing body',
'text'      => 'testing body',
'from'      => 'yourmail@yourdomain.com',
'files['.$fileName.']' => $image_data
 );

$request =  $url.'api/mail.send.json';