FanBridge API - Email Campaign Send
Example code
You can include the PHP FanBridge API SDK
library to
improve the connection handling between your site and the FanBridge API platform.
Important: We will assume here that you already have an access Token
and Secret key pair. If you don't know how to get them, please refer to the
Connecting section.
<?php
// Required files
require "fanbridge_api.php";
// Initialization
$fanbridge_api = new Fanbridge_Api(array(
'secret' => $secret,
'token' => $token));
try
{
// Inserts a new campaign
$new_campaign = json_decode($fanbridge_api->call(
'email_campaign/create',
array(
'type' => 'html',
'name' => 'My first campaign',
'subject' => 'Check my first email campaign!',
'content_html' => '<html><body>Hello everyone!</body></html>')));
// Targets the new campaign for all groups
$fanbridge_api->call(
'email_campaign/target_all',
array(
'campaign_id' => $new_campaign->id));
// Schedules the campaign
$fanbridge_api->call(
'email_campaign/schedule',
array(
'campaign_id' => $new_campaign->id,
'date_time' => 'NOW'));
}
catch (Fanbridge_Api_Exception $e)
{
// Your code...
}
The key 'NOW' means immediatly for us (in 'email_campaign/schedule'), so this campaign will
be sent as soon as possible. Please note that you could be more specific with the
groups targeting, using email_campaign/create_targeting method instead.