Hi all. I've been trying to get this code to post to a https url for some time without any remedy. I'll give you all a basic rundown, I have a site that we're trying to generate leads off of, and we have a 3rd party crm system that we use to insert those leads to. This 3rd party CRM service gave me this document: http://www.lifeinsurancesolutions.com/AddLeadWebServiceWholesale.pdf to help me implement their API, but I've done everything and the leads still seem to not be dumping into the CRM.
The URL I'm supposed to post to is: https://www.efinancial.net/addleadservice/addleadservice.asmx/AddLeadWholesale
The test form I'm using is real simple:
<form action="scripts/curlPost.php" name="myform" id="myform" method="post">
<!-- Gender --><input type="text" id="insured_1_gender" name="insured_1_gender" value="F" />
<!-- DOB --><input type="text" id="DOB" name="DOB" value="08/30/1988" />
<!-- Tobacco --><input type="text" id="insured_1_tobacco" name="insured_1_tobacco" value="none" />
<!-- First Name --><input type="text" id="first_name" name="first_name" value="test" />
<!-- Last Name --><input type="text" id="last_name" name="last_name" value="lead" />
<!-- City --><input type="text" id="address_1_city" name="address_1_city" value="austin" />
<!-- State --><input type="text" id="address_1_state" name="address_1_state" value="TX" />
<!-- Address --><input type="text" id="Address1" name="Address1" value="1234 front streeto" />
<!-- Address 2 --><input type="text" id="Address2" name="Address2" value="apt726" />
<!-- Zip Code --><input type="text" id="address_1_zip" name="address_1_zip" value="78728" />
<!-- Home Phone --><input type="text" id="phone_1" name="phone_1" value="8062313333" />
<!-- Work Phone --><input type="text" id="WorkPhone" name="WorkPhone" value="8062313333" />
<!-- Cell Phone --><input type="text" id="CellPhone" name="CellPhone" value="8062313333" />
<!-- Income --><input type="text" id="Income" name="Income" value="100000" />
<!-- Email --><input type="text" id="email" name="email" value="joo@joo.com" />
<!-- IP Address --><input type="text" id="IPAddress" name="IPAddress" value="67.78.114.48" />
<!-- Term Length --><input type="text" id="typeofinsurance" name="typeofinsurance" value="20" />
<!-- Coverage Amount --><input type="text" id="coverageamount" name="coverageamount" value="50000" />
<!-- Insurance Reason --><input type="text" id="InsuranceReason" name="InsuranceReason" value="Family Protection" />
<!-- Height --><input type="text" id="insured_1_height" name="insured_1_height" value="72" />
<!-- Weight --><input type="text" id="insured_1_weight" name="insured_1_weight" value="200" />
<!-- User Name --><input type="text" id="UserName" name="UserName" value="luisestrada" />
<!-- AuthorizationCode --><input type="text" id="AuthorizationCode" name="AuthorizationCode" value="TheLif100819091951" /><br />
<input type="submit" name="submit">
</form>
And my php code using cURL is:
<?php
error_reporting(E_ALL);
header("Content-Type: text/html");
//create variables
$alissusername = "luisestrada";
$authorizationcode = "TheLif100819091951";
$DOB = $_POST['DOB'];
$gender = $_POST['insured_1_gender'];
$tobacco = $_POST['insured_1_tobacco'];
$firstname = $_POST['first_name'];
$lastname = $_POST['last_name'];
$heightfeet = $_POST['insured_1_feet'];
$heightinches = $_POST['insured_1_inches'];
//$heightconverted = $heightfeet * 12 + $heightinches;
$heightconverted = $_POST['insured_1_height'];
$weight = $_POST['insured_1_weight'];
$termlength = $_POST['typeofinsurance'];
$coverageamount = $_POST['coverageamount'];
$premiummode = $_POST['paymentfrequency'];
$city = $_POST['address_1_city'];
$state = $_POST['address_1_state'];
$zip = $_POST['address_1_zip'];
$county = $_POST['address_1_county'];
$phone = $_POST['phone_1'];
$email = $_POST['email'];
$ip = $_SERVER['REMOTE_ADDR'];
$keyword = $_POST['keyword'];
$blank = "";
//set POST variables
$url = 'https://www.efinancial.net/addleadservice/addleadservice.asmx/AddLeadWholesale';
$fields = array(
'LastName'=>urlencode($lastname),
'FirstName'=>urlencode($firstname),
'EmailAddress'=>urlencode($email),
'Gender'=>urlencode($gender),
'DOB'=>urlencode($DOB),
'Tobacco'=>urlencode($tobacco),
'HomePhone'=>urlencode($phone),
'WorkPhone'=>urlencode($phone),
'CellPhone'=>urlencode($phone),
'Address1'=>urlencode($city),
'Address2'=>urlencode($blank),
'City'=>urlencode($city),
'State'=>urlencode($state),
'Zipcode'=>urlencode($zip),
'Income'=>urlencode($blank),
'InsuranceReason'=>urlencode($blank),
'IPAddress'=>urlencode($ip),
'TermLength'=>urlencode($termlength),
'CoverageAmount'=>urlencode($coverageamount),
'Height'=>urlencode($heightconverted),
'Weight'=>urlencode($weight),
'UserName'=>urlencode($alissusername),
'AuthorizationCode'=>urlencode($authorizationcode)
);
//url-ify the data for the POST
$counter = 0;
foreach($fields as $key=>$value) {
if ($counter > 0) {
$fields_string .= '&';
}
$fields_string .= $key.'='.$value;
$counter++;
}
rtrim($fields_string,'&');
//open connection
$ch = curl_init($url);
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_HEADER ,0); // DO NOT RETURN HTTP HEADERS
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE CONTENTS OF THE CALL
//execute post
$result = curl_exec($ch);
if(curl_exec($ch) === false) {
echo 'Curl error: ' . curl_error($ch);
} else {
echo 'Operation completed without any errors';
}
//close connection
curl_close($ch);
//echo($result . "<br>");
echo($fields_string . "<br>");
?>
Do you all see anything that I'm doing wrong? When I try to submit this in a regular form post with the url, it works fine and takes me to a page in xml that says <string>Added</string> and the lead gets added into the crm system.
Any help would be greatly appreciated, and I can donate to the person that helps me solve this.