Skip to content

Instantly share code, notes, and snippets.

@greenhornet79
Created September 23, 2015 13:48
Show Gist options
  • Save greenhornet79/17b28eb696d5ed1066ca to your computer and use it in GitHub Desktop.
Save greenhornet79/17b28eb696d5ed1066ca to your computer and use it in GitHub Desktop.
A function to add a new user to an Emma list
<?php
function add_user_to_emma( $data ) {
// http://api.myemma.com/
// Emma Authentication Variables
$account_id = "#"; // add your account id
$public_api_key = "#"; // add your public api key
$private_api_key = "#"; // add your private api key
// Form variable(s)
$email = $data['emma_email']; // this has to match the name of the form field
$first_name = $data['emma_first_name']; // this has to match the name of the form field
$last_name = $data['emma_last_name']; // this has to match the name of the form field
$groups = array(123); // add the group id (list) that you want this user to be added to
// Member data other than email should be passed in an array called "fields"
$member_data = array(
"email" => $email,
"fields" => array(
"first_name" => $first_name,
"last_name" => $last_name
),
"group_ids" => $groups
);
// Set URL
$url = "https://api.e2ma.net/".$account_id."/members/add";
// setup and execute the cURL command
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERPWD, $public_api_key . ":" . $private_api_key);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($member_data));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($member_data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$head = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment