I'm attempting to send results from a drupal webform through a cURL POST to a third party. My cURL function is not working, and I'm struggling to find my error. I have never used cURL before, so I'm not really sure how it works, or really even what it does.
From what I can tell, I'm piecing together the URL to be sent correctly, the send is just failing.
<?php
module_load_include('inc','webform','includes/webform.submissions');
$uri = $_SERVER[REQUEST_URI];
$sid = substr($uri, 20);
$submission = webform_get_submissions(array('sid' => $sid));
$nid = $submission[$sid]->nid;
$sql = db_select('webform_submitted_data', 'w');
$sql->fields('w', array('sid','cid','data'))
->condition('sid', $sid)
->condition('cid', array(1,2,3,4,5,6,7,8),'IN');
$results = $sql->execute();
$post = NULL;
$url = urlencode('http://ulm.datamark.com/services/lead_submission&client_code=DAV4516&source_code=DAVNCU');
foreach($results as $result)
{
if ($result->cid == 1) {
$post .= "first_name=" . urlencode($result->data);
} else if ($result->cid == 2) {
$post .= "&last_name=" . urlencode($result->data);
} else if ($result->cid == 3) {
$post .= "&email=" . urlencode($result->data);
} else if ($result->cid == 4) {
$post .= "&phone=" . urlencode($result->data);
} else if ($result->cid == 5) {
$who = $result->data;
} else if ($result->cid == 6) {
$post .= "&phone2=" . urlencode($result->data);
} else if ($result->cid == 8) {
$post .= "&comments=" . urlencode($result->data);
}
}
dsm($who);
dsm($url.$post);
if ($who == "fs")
{
$defaults = array(
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 4,
CURLOPT_POSTFIELDS => http_build_query($post)
);
$ch = curl_init();
curl_setopt_array($ch, ($defaults));
if( ! $result = curl_exec($ch))
{
echo "Something went wrong";
trigger_error(curl_error($ch));
}
curl_close($ch);
?>
My eyes see a couple issues:
?
in your url.