fans and counting

api FanBridge API - Email Campaign Send

This example shows you how to send an email campaign using email_campaign/create, email_campaign/target_all and email_campaign/schedule API methods.

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.
Download this example


// Required files
require "fanbridge_api.php";

// Initialization
$fanbridge_api = new Fanbridge_Api(array(
	'secret' => $secret,
	'token' => $token));

	// Inserts a new campaign
	$new_campaign = json_decode($fanbridge_api->call(
			'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
			'campaign_id' => $new_campaign->id));

	// Schedules the campaign
			'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.