php - How to add headers in sendgrid? -
i'm trying send calendar invitation on outlook using php , sendgrid. need create ics file not issue. issue need set headers. gmail recognizes ics file calendar invitation outlook not. entire code i've come i'm going in this. please help. i've searched every blog find out how can add headers such content-type , content-disposition in sendgrid no avail.
<html> <head> <title>php test</title> </head> <body> <?php include("/users/aaa/downloads/sendgrid-php/sendgrid-php.php"); include('/users/aaa/downloads//smtpapi-php/smtpapi-php.php'); $sendgrid = new sendgrid("uname", "pass"); $email = new sendgrid\email(); $ical = " content-type: text/calendar;method=request mime-version: 1.0 begin:vcalendar method:request version:2.0 prodid:-//hacksw/handcal//nonsgml v1.0//en begin:vevent uid:" . md5(uniqid(mt_rand(), true)) . "@time.co dtstamp:" . gmdate('ymd').'t'. gmdate('his') . "z dtstart:20150429t170000z dtend:20150429t035959z summary:new event has been added end:vevent end:vcalendar"; $filename = "invite.ics"; $file = fopen($filename, 'w'); fwrite($file, $ical); fclose($file); $email->addto("aaa@outlook.com") ->setfrom("aaa@example.com") ->setsubject("subject") ->setattachment($filename) ->addheader('content-type', 'multipart/alternative') ->addheader('content-disposition', 'inline'); $sendgrid->send($email); var_dump($sendgrid); try { $sendgrid->send($email); } catch(\sendgrid\exception $e) { echo $e->getcode(); foreach($e->geterrors() $er) { echo $er; } } ?> </body> </html>
unfortunately limitation of current web endpoint. use case need send on smtp instead of http. use smtpapi-php
library build x-smtpapi headers if you're using them. build smtp message library of choice, add custom headers (including x-smtpapi if needed), , send it.
example using swift mailer smtp transport
use smtpapi\header; $transport = \swift_smtptransport::newinstance('smtp.sendgrid.net', 587); $transport->setusername('sendgrid_username'); $transport->setpassword('sendgrid_password'); $mailer = \swift_mailer::newinstance($transport); $message = new \swift_message(); $message->settos(array('bar@blurdybloop.com')); $message->setfrom('foo@blurdybloop.com'); $message->setsubject('hello'); $message->setbody('%how% doing?'); $header = new header(); $header->addsubstitution('%how%', array('owl')); $message_headers = $message->getheaders(); $message_headers->addtextheader(header::name, $header->jsonstring()); try { $response = $mailer->send($message); print_r($response); } catch(\swift_transportexception $e) { print_r('bad username / password'); }
Comments
Post a Comment