Skip to content

Instantly share code, notes, and snippets.

@pije76
Forked from unbounce/unbounce-webhook-email.php
Created October 15, 2012 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pije76/3895431 to your computer and use it in GitHub Desktop.
Save pije76/3895431 to your computer and use it in GitHub Desktop.
<?php
// This is a sample PHP script that demonstrates accepting a POST from the
// Unbounce form submission webhook, and then sending an email notification.
function stripslashes_deep($value) {
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
// First, grab the form data. Some things to note:
// 1. PHP replaces the '.' in 'data.json' with an underscore.
// 2. Your fields names will appear in the JSON data in all lower-case,
// with underscores for spaces.
// 3. We need to handle the case where PHP's 'magic_quotes_gpc' option
// is enabled and automatically escapes quotation marks.
if (get_magic_quotes_gpc()) {
$unescaped_post_data = stripslashes_deep($_POST);
} else {
$unescaped_post_data = $_POST;
}
$form_data = json_decode($unescaped_post_data['data_json']);
// If your form data has an 'Email Address' field, here's how you extract it:
$email_address = $form_data->email_address[0];
// Grab the remaining page data...
$page_id = $_POST['page_id'];
$page_url = $_POST['page_url'];
$variant = $_POST['variant'];
// Assemble the body of the email...
$message_body = <<<EOM
Email: $email_address \n
Page ID: $page_id \n
URL: $page_url \n
Variant: $variant \n
EOM;
mail('Your Email Address',
'New Unbounce Form Submission!',
$message_body);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment