Skip to content

Instantly share code, notes, and snippets.

@travelton
Created November 27, 2013 18:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save travelton/7680617 to your computer and use it in GitHub Desktop.
Save travelton/7680617 to your computer and use it in GitHub Desktop.
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