首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Sendgrid附件- pdf php

Sendgrid附件- pdf php
EN

Stack Overflow用户
提问于 2016-09-09 11:52:58
回答 1查看 1.1K关注 0票数 0

我正在使用sendgrid从我的应用程序发送邮件,一切都很好,直到我尝试添加一个附件(一个在页面中生成并存储为变量的pdf )。

pdf发送如果我使用标准的php邮件函数,但是我想把它添加到我的sendgrid邮件中,我正在使用以下代码,但没有任何运气:

代码语言:javascript
复制
        $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>";

我尝试过->setsetFiles()和->setAttachment(),但似乎都不起作用,并收到以下错误消息:

09-Sep-2016 03:55:19 UTC PHP致命错误:未捕获异常'Guzzle\Common\Exception\InvalidArgumentException‘,并显示消息'Unable to opens%pdf-1.4 3 0 obj

有谁知道怎么做吗?

EN

回答 1

Stack Overflow用户

发布于 2017-08-29 18:43:09

代码语言:javascript
复制
`#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'; 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39403598

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档