3
我正試圖使用php和sendgrid在outlook上發送日曆邀請。所以我需要創建一個不是問題的ics文件。問題是我需要設置標題。 Gmail會將ics文件識別爲日曆邀請,但Outlook不會。這是我提出的完整代碼,但我無法在這裏完成。請幫忙。我搜索了每個博客,以瞭解如何在sendgrid中添加頭文件(如content-type和content-disposition),但無濟於事。如何在sendgrid中添加標題?
<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("[email protected]")
->setFrom("[email protected]")
->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>