• phosphor
  • NEWBIE
  • 0 Points
  • Member since 2005

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
We need assistance getting a web to lead form processed in PHP. We have the script setup to email, write the data to mySQL and POST the data to SalesForce. We have not been able to get the SalesForce part to work.

Please help.
We are trying to take form data and process it with a PHP script to send email notification, populate an internal mySQL database and post the data to salesforce. The email and mySql functions are working fine, Salesforce is not.

Here is the form we are trying to populate SalesForce with:

http://www.ebreastaug.com/bacontactb.php?goto=1&state=NY&metro=White%20Plains%20Area

-- debugging is turned on here and the redirect is turned off

We're posting the data to salesforce via a function called sendtohost() See Below

The salesforce.php (see below) script sets up the data to be sent to salesforce, then sendtohost sends it.

Notice toward the bottom of salesforce.php is the retURL variable -- that's the one that is returning us to the thankyou page. Salesforce is seeing that, so it must be seeing everything else... the line that says echo "
$result
"; is what prints all the output from the salesforce server, saying that the request has been queued, etc etc




/* sendToHost
* ~~~~~~~~~~
* Params:
* $host - Just the hostname. No http:// or
/path/to/file.html portions
* $method - get or post, case-insensitive
* $path - The /path/to/file.html part
* $data - The query string, without initial question mark
* $useragent - If true, 'MSIE' will be sent as
the User-Agent (optional)
*
* Examples:
* sendToHost('www.google.com','get','/search','q=php_imlib');
* sendToHost('www.example.com','post','/some_script.cgi',
* 'param=First+Param&second=Second+param');
*/

function sendToHost($host,$method,$path,$data,$useragent=0)
{
// Supply a default method of GET if the one passed was empty
if (empty($method)) {
$method = 'GET';
}
$method = strtoupper($method);
$fp = fsockopen($host, 80);
if ($method == 'GET') {
$path .= '?' . $data;
}
fputs($fp, "$method $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp,"Content-type: application/x-www-form- urlencoded\r\n");
fputs($fp, "Content-length: " . strlen($data) . "\r\n");
if ($useragent) {
fputs($fp, "User-Agent: MSIE\r\n");
}
fputs($fp, "Connection: close\r\n\r\n");
if ($method == 'POST') {
fputs($fp, $data);
}

while (!feof($fp)) {
$buf .= fgets($fp,128);
}
fclose($fp);
return $buf;
}

?>


/************************** SALES FORCE CONNECTION ******************8
*
*
************************** SALES FORCE CONNECTION *****************/

include("inc/sendtohost.php");

/* sendToHost
* ~~~~~~~~~~
* Params:
* $host - Just the hostname. No http:// or
/path/to/file.html portions
* $method - get or post, case-insensitive
* $path - The /path/to/file.html part
* $data - The query string, without initial question mark
* $useragent - If true, 'MSIE' will be sent as
the User-Agent (optional)
*
* Examples:
* sendToHost('www.google.com','get','/search','q=php_imlib');
* sendToHost('www.example.com','post','/some_script.cgi',
* 'param=First+Param&second=Second+param');
*/


$host = "www.salesforce.com";
$method = "post";
$path = "/servlet/servlet.WebToLead?encoding=UTF-8";

$data = "";
$data .= "debug=\"1\"&";
$data .= "debugEmail=\"jasono@awmed.com\"&";
$data .= "oid=\"00D300000001EcU\"&";
$data .= "lead_source=\"Patient Web Lead\"&";
$data .= "00N30000000xiVf=\"$goto\"&";
$data .= "00N30000000xkUZ=\"$metro\"&";
$data .= "00N30000000xkWL=\"$docName\"&";
$data .= "00N30000000xlJh=\"$abbrev\"&";
$data .= "00N30000000xkcx=\"$Send_info_on_txt\"&";
$data .= "salutation=\"$salutation\"&";
$data .= "first_name=\"$first\"&";
$data .= "last_name=\"$last\"&";
$data .= "email=\"$email\"&";
$data .= "phone=\"$phone\"&";
$data .= "street=\"$address1\"&";
$data .= "city=\"$city\"&";
$data .= "state=\"$cstate\"&";
$data .= "zip=\"$zip\"&";
$data .= "00N30000000xjcX=\"$financing\"&";
$data .= "00N30000000xkWz=\"$gender\"&";
$data .= "00N30000000xkZt=\"$age\"&";
$data .= "00N30000000xkTD=\"$notes\"&";
$data .= "retURL=\"http://www.ebreastaug.com/thank-you.html\"";
//$data .= "=&";

$result = sendToHost( $host, $method, $path, $data );

echo "
$result
";




/************************** END SALES FORCE CONNECTION ******************
*
*
************************** END SALES FORCE CONNECTION *****************/
?>