+ Start a Discussion

Posting to servlet.WebToLead from PHP : anyone got it working'


I'm trying to POST to WebToLead service through the servlet http://www.salesforce.com/servlet/servlet.WebToLead however I do not seem to beable to get the thing to work. The HTML generated from salesforce.com works fine, then I would presume posting the same information as in the form to http://www.salesforce.com/servlet/servlet.WebToLead would also work but no leads are generated in salesforce.com.

Has anyone got this to work from PHP? Has anyone got some working example code?

p.s. I do not want to use the API.

Thanks for your time


Couple of possibilities:

1. You are checking for the new Lead too soon.  It takes a few seconds to show, sometimes minutes.

2. Make sure all those *hidden* fields are being passed too.  Especially OID.



require_once "HTTP/Request.php";
$req =& new HTTP_Request("http://www.salesforce.com/servlet/servlet.WebToLead–encoding=UTF-8");
$msg = "";
foreach($_REQUEST as $InputName => $InputValue)
  $msg .= $InputName . " = " . $InputValue . " \n";
$response = $req-> sendRequest();
if (PEAR::isError($response)) {
      $msg .= "Error: " . $response->getMessage() . "\n" . 
     mail('itlog@selectbs.com','Failed Web-to-Lead',$msg);
$code = $req->getResponseCode();
// echo $code, "\n";

Here's a sample which generates a post to the servlet.

It's called from a modified version of the salesforce generated form. The generated form is changed to post all the same data to this php routine, which then re-posts it to salesforce.


Hi there,

this looks really interesting - please could you tell me what is in the include in line 2, and I'm struggling a bit with a task very similar to this!