+ Start a Discussion
Chris McKenzieChris McKenzie 

Web To Lead via CURL is not working anymore

Recently I got stuck with storing leads to SF via CURL calls, it was working perfectly before and somehow it stopped a few weeks ago.

I must emphasize that I didn't do any code changes which could possibly cause this function to fail.

Here is a part of my code:

//Initialize the $kv array for later use
$kv = array();

foreach ($prepare_data as $key => $value) {
    $kv[] = stripslashes($key)."=".stripslashes($value);

//Create a query string with join function separted by &
$query_string = join("&", $kv);

//Check to see if cURL is installed ...
if (function_exists('curl_init')) {

    $url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';

    //Open cURL connection
    $ch = curl_init();

    //Set the url, number of POST vars, POST data
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, count($kv));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);

    //Set some settings that make it all work :)
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, FALSE);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);

    //Execute SalesForce web to lead PHP cURL
    $result = curl_exec($ch);

    //close cURL connection


$prepare_data variable has key/value pairing of SF fields. Keys are set from the HTML generated form.

I would appreciate help from someone who else have/had similar issues to try to solve this.

Thanks in advance


Can you say more about exactly how it's "not working"? Maybe try printing the details of the transfer and pasting results back here.

Chris McKenzieChris McKenzie


This is something I can't really explain why occurred. Everything was working and suddenly the leads stopped being saved to SF.

Here is the curl request info you asked for

    [url] => https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8
    [content_type] => text/html;charset=UTF-8
    [http_code] => 302
    [header_size] => 368
    [request_size] => 500
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.208093
    [namelookup_time] => 0.002432
    [connect_time] => 0.023252
    [pretransfer_time] => 0.083559
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => 0
    [upload_content_length] => 0
    [starttransfer_time] => 0.208045
    [redirect_time] => 0
Chris McKenzieChris McKenzie
You'll notice the URL change, but this is something SF recommended to do recently.
Hi - There should have been a couple more values in the output. I'm looking specifically for [redirect_url]. Can you check your output for this value?
Chris McKenzieChris McKenzie

That's all, there is no "redirect_url".

Do you maybe have an idea why it's stopped working suddenly without code changes?

Hi - sorry to be so late getting back. I'm wondering if Salesforce is redirecting your post becuase of a TLS problem. Have you recently activated the TLS update?
Chris McKenzieChris McKenzie


No problem at all, I'm glad that you're trying to help me anyway.

Hm... I don't think that TLS update is done, I think TLS 1.0 is still active.

But shouldn't I receive any error message about that?

Chris McKenzieChris McKenzie

I think I found it and it seems that you're right. I've turned on CURLOPT_HEADER and this is how response header looks like

string(368) "HTTP/1.1 302 Found
Date: Wed, 08 Feb 2017 09:26:48 GMT
Cache-Control: private,s-maxage=0
Set-Cookie: BrowserId=pFfLlBowSEiOLw_LnMz6ag;Path=/;Domain=.salesforce.com;Expires=Sun, 09-Apr-2017 09:26:48 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: text/html;charset=UTF-8
Location: https://eu6.salesforce.com/secur/weakhttps.jsp?l=1
Content-Length: 0

Pierre HausheerPierre Hausheer
I had the same issue.
First, I use the following to debug.
$result = curl_exec($ch);
	echo 'Curl error: ' . curl_error($ch).'<br>';
I received this error: SSL certificate problem: unable to get local issuer certificate
I found this solution:
Which advises to add the following:
curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0);
It worked, however, I didn't think that it was wise to disable host name verification.
Then I found the following solution:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, 'cacert.pem');
Where 'cacert.pem' was downloaded at the following location:
And then save at the same level than my PHP.
Now it works all fine.

Retrospectively, I believed that the issue appeared when I move my website on Azure which may have different default parameters for curl.

Hope it helps.