Googleカレンダーに正常にインポートされた.icsファイルを生成しようとしています。 Googleカレンダーは特に難しいことが証明されています(私はOutlookとApple iCalが完全に機能しています)。誰かがGoogleカレンダーで動作するiCalendarジェネレータ関数を作成しましたか?
誰かが、右のヘッダーを作成し、Googleカレンダーで動作することが証明されているイベントを挿入するPHP関数またはクラスを持っていますか?
Googleカレンダーに正常にインポートされた.icsファイルを生成しようとしています。 Googleカレンダーは特に難しいことが証明されています(私はOutlookとApple iCalが完全に機能しています)。誰かがGoogleカレンダーで動作するiCalendarジェネレータ関数を作成しましたか?
誰かが、右のヘッダーを作成し、Googleカレンダーで動作することが証明されているイベントを挿入するPHP関数またはクラスを持っていますか?
同様のことをしましたが、iCalの代わりにURLを作成しました。
は、フォームに必要事項を記入し、私はただの変数と詳細情報を交換するために別のものを作成したのiCalを作成するために使用したPHPファイルで、その後HTMLを生成https://support.google.com/calendar/answer/3033039
をチェックしてください。
EG:
if($calType === "iCal"){
//set correct content-type-header
header('Content-Disposition: attachment; filename=AddToCalendar.ics');
header('Content-Type: text/calendar; charset=utf-8');
$desc = str_replace("\n", '\n', $desc);
$desc = str_replace(array("\r","\n","\r"), '', $desc);
$ical = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Smartershows.com//TheBatteryShow//EN
X-WR-CALNAME;CHARSET=utf-8:".$subj."
METHOD:PUBLISH
X-MS-OLK-FORCEINSPECTOROPEN:TRUE
BEGIN:VEVENT
SUMMARY;CHARSET=utf-8:".$subj."
LOCATION;CHARSET=utf-8:".$loc."
URL:".$url."
UID:30fc985de98ed0dabfeb13722e3c82259fcd33e3
DESCRIPTION:".$desc."
DTSTART:".$sDate."T".$sTime."
DTEND:".$eDate."T".$eTime."
END:VEVENT
END:VCALENDAR";
return $ical;
exit;
}else if($calType === "gCal"){
$href = "http://www.google.com/calendar/event?";
$href .= "action=TEMPLATE";
$href .= "&text=".urlencode($subj);
$href .= "&dates=".$sDate."T".$sTime."/".$eDate."T".$eTime;
$href .= "&details=".urlencode($desc);
$href .= "&location=".urlencode($loc);
$href .= "&trp=false";
$href .= "&sprop=".urlencode($subj);
$href .= "&sprop=name:".urlencode($url);
return '<a href="'.$href.'" target="_blank"><strong>Download for Gmail</strong></a>';
}
そうで最初のブロックのiCalを作っていると第二は、Googleが取ると、カレンダーのページを移入するURLを構築するために、同じ情報を取っている場合。
しかし、これの欠点は、あなたは説明に基本的なものを入れることができるということです...派手なhtmlや何か...あなたがhtmlencodeすべて私は推測するが、
HotmailとYahooメールは両方ともこの方法でカレンダーを作成できますが、残念なことにどちらもあなたが使用できるリンクを事前に生成する素晴らしいツールはありません。
希望すると便利です。
これは古いもので、唯一の回答が受け入れられなかったため、以下のコードで問題が修正されているかどうかは不明です。しかし、私は自分の検索でこれを見つけて、私が持っていたバグを修正しようとしました。そして、私は解決策を得ました。私はそれを分かち合うと考えました。以下のコードは、最新のOutlookとGmailでテストされています。
私のバグの原因は、イベントの詳細として\r\n
の代わりに\n
を使用していたことです。したがって、以下に示すように、私はイベントのために\r\n
を使用し、PHPはそれを正しく処理するようにeverythignのために\ nを使用します。おそらく同様の問題がGmailの問題を引き起こしていたでしょうか?
警告、このコードは、ヘッダインジェクションを防ぐために何もしない、してください 使用責任;-)
<?php
date_default_timezone_set('America/New_York');
//CONFIGURE HERE
$fromName = "John Doe";
$fromEmail = "[email protected]";
$toName = "Your Name";
$toEmail = '[email protected]';
$start = new DateTime('2017-08-15 15:00');
$end = new DateTime('2017-08-15 16:00');
$summary = "Hello World Event";
//END CONFIGURATION
$uid = "";
$headers = array();
$boundary = "_CAL_" . uniqid("B",true) . "_B_";
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-Type: multipart/alternative; boundary=\"".$boundary."\"";
$headers[] = "To: \"{$toName}\" <{$toEmail}>";
$headers[] = "From: \"{$fromName}\" <{$fromEmail}>";
$calendarLines = array(
"BEGIN:VCALENDAR",
"METHOD:REQUEST",
"PRODID:-//PHP//MeetingRequest//EN",
"VERSION:2.0",
"BEGIN:VEVENT",
"ORGANIZER;CN={$fromName}:MAILTO:{$fromEmail}",
"ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN={$toName}:MAILTO:{$toEmail}",
"DESCRIPTION:{$summary}",
"SUMMARY:{$summary}",
"DTSTART:".$start->setTimezone(new DateTimeZone('UTC'))->format('Ymd\THis\Z'),
"DTEND:".$end->setTimezone(new DateTimeZone('UTC'))->format('Ymd\THis\Z'),
"UID:{$uid}",
"CLASS:PUBLIC",
"PRIORITY:5",
"DTSTAMP:".gmdate('Ymd\THis\Z'),
"TRANSP:OPAQUE",
"STATUS:CONFIRMED",
"SEQUENCE:0",
"LOCATION:123 Any Street",
"BEGIN:VALARM",
"ACTION:DISPLAY",
"DESCRIPTION:REMINDER",
"TRIGGER;RELATED=START:-PT15M",
"END:VALARM",
"END:VEVENT",
"END:VCALENDAR"
);
$calendarBase64 = base64_encode(implode("\r\n",$calendarLines));
//ensure we don't have lines longer than 70 characters for older computers:
$calendarResult = wordwrap($calendarBase64,68,"\n",true);
$emailLines = array(
"--{$boundary}",
"Content-Type: text/html; charset=\"iso - 8859 - 1\"",
"Content-Transfer-Encoding: quoted-printable",
"",
"<html><body>",
"<h1>Hello World</h1>",
"<p>This is a calendar event test</p>",
"</body></html>",
"",
"--{$boundary}",
"Content-Type: text/calendar; charset=\"utf - 8\"; method=REQUEST",
"Content-Transfer-Encoding: base64",
"",
$calendarResult,
"",
"--{$boundary}--"
);
$emailContent = implode("\n",$emailLines);
$headersResult = implode("\n",$headers);
mail($toEmail, $summary, $emailContent, $headersResult);
echo("<pre>".htmlentities($headersResult)."\n\n".htmlentities($emailContent)."</pre>");
echo("<br /><br />");
echo("<pre>".base64_decode($calendarResult)."</pre>");