Skip to content

Instantly share code, notes, and snippets.

@thebiltheory
Last active December 16, 2015 16:01
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 thebiltheory/8388fa9e048507ecaec1 to your computer and use it in GitHub Desktop.
Save thebiltheory/8388fa9e048507ecaec1 to your computer and use it in GitHub Desktop.
Webhook to send instapage form to silverpop database
<?php
/**
* Silverpop Instapage webhook
*/
// Instapage System vars
$page_id = $_POST[ 'page_id' ];
$page_url = $_POST[ 'page_url' ];
$variant = $_POST[ 'variant' ];
/**
* DOWNLOAD THE COMPOSER DEPENDENCIE
* https://github.com/simpleweb/SilverpopPHP
**/
//-------------| SILVER POP - CONFIG |----------------
// Include the library
require_once 'vendor/autoload.php';
// Require the Silverpop Namespace
use Silverpop\EngagePod;
// Sent mail function
function shooting_mail(){
//--| INSTAPAGE VAR - CONFIG |--
// Mapp all instapage fields to a variable
$action = trim( strip_tags( $_POST[ 'action' ] ) );
$name = trim( strip_tags( $_POST[ 'name' ] ) );
$firstname = trim( strip_tags( $_POST[ 'firstname' ] ) );
$email = trim( strip_tags( $_POST[ 'email' ] ) );
$phone = trim( strip_tags( $_POST[ 'phone' ] ) );
$country = trim( strip_tags( $_POST[ 'country' ] ) );
$source = trim( strip_tags( $_POST[ 'source' ] ) );
//----
/*
* Add an hidden field to capture the "source"
*/
// Set some useful silverpop variables
$databaseID = 'xxx'; //Your Database ID
// Silverpop login
$silverpop = new EngagePod(array(
'username' => 'xxx',
'password' => 'xxx',
'engage_server' => 3,
));
// Add a record to a contact
// Check EngagedPod.php file for some doc on Silverpop functions
$recipientID = $silverpop->addContact(
$databaseID,
true,
array(
'name' => $name,
'firstname' => $firstname,
'email' => $email,
'phone' => $phone,
'country' => $country
),
false,
true,
true
);
}
//------------------------------------------------
//-------------| FORM ACTION |--------------------
// Add a hidden input on top of the form with send_mail as value.
// <input type="hidden" name="action" value="send_mail">
$_action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
if ( 'send_mail' == $_action ) {
shooting_mail();
exit();
}
//------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment