function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TimL.ax219TimL.ax219 

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

Hi,

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
Tim
dhruvadhruva

Tim,

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.

ScotScot

Code:

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


 
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.

 

austenozzyaustenozzy
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!

thanks,

Austen