Last active
December 16, 2015 16:01
-
-
Save thebiltheory/8388fa9e048507ecaec1 to your computer and use it in GitHub Desktop.
Webhook to send instapage form to silverpop database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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