Skip to content

Instantly share code, notes, and snippets.

@jonesch
Created October 5, 2012 18:54
Show Gist options
  • Save jonesch/3841680 to your computer and use it in GitHub Desktop.
Save jonesch/3841680 to your computer and use it in GitHub Desktop.
Submitting to Exact Target with cURL
<?php //I am using this for an AJAX call, and checking my responses against the success or failure that it is echoing back.
//create array of data to be posted
$full_name = stripslashes(trim(strip_tags($_POST['full_name'])));
$email_address = stripslashes(trim(strip_tags($_POST['email_address'])));
if(!empty($full_name) && !empty($email_address)){
$post_data['MID'] = "10488043";
$post_data['Full Name'] = $full_name;
$post_data['Email Address'] = $email_address;
$post_data['thx'] = '';
$post_data['err'] = '';
//create the final string to be posted using implode()
$post_str = implode ('&', $post_data);
foreach($data as $key=>$val) {
$post_string .= $key.'='.urlencode($val).'&';
}
$post_str = substr($post_str, 0, -1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://cl.exct.net/subscribe.aspx?lid=18086381');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close($ch);
echo 'success';
} else {
echo 'failure';
}
?>
@xonumaxwell
Copy link

Hello jones,
i want to submit an html form but the form does not do the submission by itself ,in the action part of the form i have a php file that is collecting the data and then would now submit into an api(8 fields) i have so that i receive a response and further have a redirect link to the page i should go to once the data submission is successful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment