Created
November 27, 2013 18:22
-
-
Save travelton/7680617 to your computer and use it in GitHub Desktop.
Send iCal with Mailgun PHP SDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'vendor/autoload.php'; | |
use Mailgun\Mailgun; | |
use Sabre\VObject; | |
// Instantiate the Mailgun Client | |
$mg = new Mailgun("MG-API-KEY"); | |
$domain = "Your Domain"; | |
// Create calendar invite with Sabre VOject lib | |
$cal = new VObject\Component\VCalendar(); | |
// Create a meeting invite that lasts 2 hours on the same day | |
$vevent = $cal->add ( 'VEVENT', array( | |
'summary' => $subject, | |
'location' => 'Meeting room 1', | |
'dtstart' => new DateTime( $mtg_date . ' 09:00:00', new \DateTimeZone( 'America/Toronto' ) ), | |
'dtend' => new DateTime( $mtg_date . ' 11:00:00', new \DateTimeZone( 'America/Toronto' ) ), | |
'method' => 'REQUEST' | |
) ); | |
// Make iCal String | |
$data = $cal->serialize (); | |
// Dump the string to a temp file | |
$tempFile = sys_get_temp_dir() . "/invite.ics"; | |
$fileHandle = fopen($tempFile, "w"); | |
fwrite($fileHandle, $data); | |
// Send the message | |
$mg->sendMessage($domain, array('from' => '[email protected]', | |
'to' => '[email protected]', | |
'subject' => 'Meeting Invite', | |
'o:campaign' => 'mailgun_campaign_id', | |
'text' => 'Anything can go here'), | |
array('attachment' => array($tempFile))); | |
// Kill the temp file | |
unlink($tempFile); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment