我正在使用sendgrid从我的应用程序发送邮件,一切都很好,直到我尝试添加一个附件(一个在页面中生成并存储为变量的pdf )。
pdf发送如果我使用标准的php邮件函数,但是我想把它添加到我的sendgrid邮件中,我正在使用以下代码,但没有任何运气:
$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
有谁知道怎么做吗?
发布于 2017-08-29 18:43:09
`#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'; https://stackoverflow.com/questions/39403598
复制相似问题