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
yo22yo22 

Web to Lead from PHP script

Hi,
New to SalesForce.
 
How can I send Web to Lead from and existing PHP script without a form (without user click)?
 
I have a PHP script that does some logis then sends a personalized email depanding on params and result of logic.
I want it to also send a Web to Lead with the user datails and the generated email.
 
anyone can help?
 
Thanks
ThomasGThomasG
Hello,

When I want to send Web to Lead data with no form, I just use a little function that lets me send POST data to an address.

The function :

Code:
<—php
function sendToHost($host,$path,$data,$method)
{
 $fp = fsockopen($host, 80);
 if ($fp)
 {
  if ($method === 'GET')
         $path .= '–' . $data;
 
  $out = "$method $path HTTP/1.1\r\n";
  $out .= "Host: $host\r\n";
  $out .= "Content-type: application/x-www-form-urlencoded\r\n";
  
  if ($method === 'POST')
  {
   $out .= "Content-length: " . strlen($data) . "\r\n";
   $out .= "Connection: close\r\n\r\n";
   $out .= $data;
  }
  else
   $out .= "Connection: close\r\n\r\n";

  fwrite($fp, $out);
  $buf = '';
  while (!feof($fp))
   $buf .= fgets($fp, 128);

  fclose($fp);
  return $buf;
 }
}
˜>

 Example of using this function in a page:

 
Code:
sendToHost('www.salesforce.com', '/servlet/servlet.WebToLead—encoding=utf-8',
   '&last_name='.$last_name.
   '&country='.$country.
   '&email='.$email.
   '&oid='.$yourSalesforceOID.
   '&lead_source='.$lead_source,
   'POST');


Hope that helps.