Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to send an email with Mandrill using a SugarOutfitters Webhook for a SugarCRM Add-on Sale
// load up mandrill
// get the webhook response
// decode the json data into a php object
$body = @file_get_contents('php://input');
$response = json_decode($body);
// the webhook property tells us exactly which webhook event was fired
// so let's create a case for a few webhooks
switch ($response->webhook)
case 'sale_new':
// Someone purchased your add-on
class SugarOutfittersHelper
public static function sale_new($response)
$addon = $response->data->addon; // the addon that was purchased
$lineitem = $response->data->lineitem; // we give you the lineitem because you may have multiple purchase plans for an add-on
$member = $response->data->member; // your new customer!
$licensekey = $response->data->licensekey; // if you're using SugarOutfitters lincense keys, the details of the license key are listed here
// let's send them an email
$mandrill = new Mandrill(MANDRILL_APIKEY);
$message = array(
'text' => "Hi there, thanks for giving SugarChimp a try.\n\nDo you have any questions about the integration?\n\nCheers!\nChad",
'subject' => 'MailChimp & Sugar Integration',
'from_email' => '',
'from_name' => 'Chad Hutchins',
'to' => array(
'email' => $member->email,
'type' => 'to'
'headers' => array('Reply-To' => ''),
'tags' => array('onboarding-welcome'),
echo "Email sent.<br>";
catch(Mandrill_Error $e)
// Mandrill errors are thrown as exceptions
echo 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage() . "<br>";
// notify or log this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment