Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Send iCal with Mailgun PHP SDK
<?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' => 'bob@example.com',
'to' => 'recipient@domain.com',
'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
You can’t perform that action at this time.