You need to sign in to do that
Don't have an account?

Web-To-Lead using PHP Anyone??
I've been searching this for a long time, and I want to be able to send the web-to-lead form using PHP only.
Other people have been trying this, and I've been reading through all the comments, but still haven't been able to figure it out. Currently i'm still trying the fsockopen method. Salesforce said they would get back to me on it.... but they haven't. Anyway this is the script:
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: text/html; charset=UTF-8\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;
}
I've tried using it by sending arrays and strings in different formats, such as:
$info = 'oid=\"XXXXXXXXXXX\"' . '&';
$info .= 'retURL=\"XXXXXXXXXXXXXXX\"' . '&';
$info .= 'last_name=\"Yung\"' . '&';
w/o the escapes and also:
'oid' => 'oid=XXXXXXXXXXX',
'retURL' => 'retURL=XXXXXXXXXXXXXXX',
'last_name' => 'Yung',
etc.
I don't want to validate/submit forms with Javascript, and my other idea is having the user confirm the details and submit to salesforce using hidden fields (but spammers can thus clone the page and spam me) while keeping the data in sessions (haven't tested this yet). Anyhelp would REALLY be appreciated, thanks!
Other people have been trying this, and I've been reading through all the comments, but still haven't been able to figure it out. Currently i'm still trying the fsockopen method. Salesforce said they would get back to me on it.... but they haven't. Anyway this is the script:
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: text/html; charset=UTF-8\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;
}
I've tried using it by sending arrays and strings in different formats, such as:
$info = 'oid=\"XXXXXXXXXXX\"' . '&';
$info .= 'retURL=\"XXXXXXXXXXXXXXX\"' . '&';
$info .= 'last_name=\"Yung\"' . '&';
w/o the escapes and also:
'oid' => 'oid=XXXXXXXXXXX',
'retURL' => 'retURL=XXXXXXXXXXXXXXX',
'last_name' => 'Yung',
etc.
I don't want to validate/submit forms with Javascript, and my other idea is having the user confirm the details and submit to salesforce using hidden fields (but spammers can thus clone the page and spam me) while keeping the data in sessions (haven't tested this yet). Anyhelp would REALLY be appreciated, thanks!
application/x-www-form-urlencoded
Note: I haven't cleaned up the code, so obviously modify it for yourself =)
<?PHP
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;
}
$info = 'oid=0000YOURID' . '&';
$info .= 'retURL=http://URL.COM' . '&';
$info .= 'last_name=TEST FIELD' . '&';
$info .= 'lead_source=SOURCE FROM HERE!' . '&';
$info .= 'company=COMPANY NAME';
$sent = sendToHost('www.salesforce.com','post','/servlet/servlet.WebToLead?encoding=UTF-8',$info);
echo $sent;
?>
For those willing to use a web2lead form using their own existing online forms (whatever language the form is based on, php, asp, html...) instead of using the default salesforce wen2lead generated code, you should be interrested in trying FormVester for AppExchange.
The application allows to generate new leads in salesforce from any of you existing online forms (simply insert a javascript snipet code in your website pages). FormVester has a deduplicate function, so that it always checks if the lead already exists in salesforce before generating it. If the lead already exists, the lead is simply updated.
Hope it can help. -