GetResponse is an email marketing platform. They provide several ways to integrate with your website. Enables to create custom fields through GetResponse Dashboard. It’s a simple implementation with their provided out-of-the-box services.
In my case, I had to integrate GetResponse with my website customer registration form which was custom built.
I had to use CURL for accessing the provided authentication as browsers do not allow CORS(Cross-Origin Resource Sharing).
Firstly, let’s create a file named curl.php and add the following code
<?php
$authorization = “X-Auth-Token: api-key xxxx xxxx xxxx xxxx xxxx xxxx xxxx”;
$ch = curl_init();
$name = $_POST[“name”];
$email = $_POST[“email”];
$data = array (
‘name’ => $name,
‘email’ => $email,
‘campaign’ => array(‘campaignId’=>’xxxxx’),
‘ipAddress’=> $_SERVER[‘REMOTE_ADDR’]
);
$data_string = json_encode($data);
curl_setopt($ch, CURLOPT_URL,”https://api.getresponse.com/v3/contacts");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-Type: application/json’ , $authorization ));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
// Receive server response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
print_r($server_output);
curl_close ($ch);
?>
Next, we need to create a file to push the data via AJAX. Let’s name that file as submit.js. This is how it will look.
$(document).on('submit', 'form', function (e) {
e.preventDefault();
var userName = $('#getName').val();
var userEmail = $('#getEmail').val();
var data = $(this).serializeArray();
data.push({ name: 'action', value: 'check_if_tus_form_submit' }, { name: 'tus_register_submit', value: 'yes' });
$.ajax({
type: "POST",
url: 'curl.php',
data: { name: userName, email: userEmail },
success: function(data){}
});
});
Leave a comment