我正在尝试使用php和sendgrid在outlook上发送日历邀请。所以我需要创建一个ics文件,这不是问题。问题在于我需要设置头部信息。Gmail将ics文件识别为日历邀请,但outlook没有。这是我想到的全部代码,但我在这方面一无所获。请帮忙。我已经搜索了每个博客,想找出如何在sendgrid中添加content-type和content-disposition等头部信息,但没有任何结果。
<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() as $er) {
echo $er;
}
}
?>
</body>
</html>