Skip to content

Instantly share code, notes, and snippets.

@jonesch
Created October 5, 2012 18:54
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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';
}
?>
@ehCincy
Copy link

ehCincy commented Nov 26, 2012

Jones,

I am in the process of building a PHP cURL for submissions to Exact Target.
My client would like the form info submitted and also emailed to them.
Wondering if I can do the same with your AJAX call?

@jonesch
Copy link
Author

jonesch commented May 1, 2013

Hello Cincy,
Sorry for the late reply, but you can def. do that within the same AJAX call. After you echo 'success', you can build a form using PHP's mail function. You should be able to get started using php.net/mail as a reference.
I hope that works out for yah!

@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