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
jab1972jab1972 

php form to mail and salesforce lead creation

Hi all,

I want to create leads in saleforce via my company's website contact form, but I also want keep the form emailing to a specified email address. The form uses a standard php form to mail script, but after trying various other options including the ‘web to lead’ route, I cannot get round the single submission of the form to either source. Can anyone tell me if there is a way in php to do both??


werewolfwerewolf
I'm not sure you really need PHP for this.  Why not just make a Web To Lead form and then make a workflow email message that generates an email whenever a lead is created by that route?
werewolfwerewolf
That is, make your workflow email mimic whatever was going to that email address before.  Why do you want to do that, anyway?

Another option to explore would be Email Services.  Look it up in Help & Training.
toivotoivo
Hi,

I create webleads from PHP using curl:

Code:
<?php

/**
 * @Salesforce weblead example
 * @date  20080614
 * @author Toivo Talikka
 */

$sfdc_url = 'http://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
$user_agent = ' Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12';

$form_vars = array();
$form_vars['oid'] = $my_oid;
$form_vars['Campaign_ID'] = $my_campaign_id;
$form_vars['lead_source'] = 'Website';
$form_vars['company'] = $company;;
$form_vars['title'] = $title;
$form_vars['first_name'] = $first_name;
$form_vars['last_name'] = $last_name;
$form_vars['middle_name'] = $middle_name;
$form_vars['phone'] = $phone;
$form_vars['mobile'] = $mobile;
$form_vars['fax'] = $fax;
$form_vars['address'] = $address;
$form_vars['city'] = $city;
$form_vars['state'] = $state;
$form_vars['country'] = $country;
$form_vars['zip'] = $zip;
$form_vars['email'] = $user_email;

$post_data = '';
foreach ($form_vars as $var => $value) {
 if (trim($value)) {
  $post_data .= urlencode($var).'='.urlencode($value).'&';
 }
}
// drop last &
$post_data = substr($post_data, 0, -1);
// get curl handle
@$ch = curl_init();
if ($ch !== false) {
 curl_setopt($ch, CURLOPT_URL, $sfdc_url);
 curl_setopt($ch, CURLOPT_REFERER, 'http://example.com.com');
 curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);  // may not be needed
 curl_setopt($ch, CURLOPT_POST, 1); // POST
 curl_setopt($ch, CURLOPT_HEADER, 0); // do not return http headers
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  // transfer the return as string
 curl_setopt($ch, CURLOPT_PROXY, '192.168.2.9');  // optional proxy
 curl_setopt($ch, CURLOPT_PROXYPORT, 3128);  // as above
 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); // contents of POST

 $curl_result = @curl_exec($ch);
 $errnum = curl_errno($ch);
 if ($errnum != 0) {
     $curl_error = curl_error($ch);
     $msg = date('Y-m-d-H-i-s') . " sfdc form: ".$et_url." : status: ".$errnum." - ".$curl_error;
     error_log($msg);
 } else {
  curl_close($ch);
  // $curl_result contains the response from salesforce
 }
} else {
 $msg = date('Y-m-d-H-i-s') . " sfdc form: error in getting curl handle";
 error_log($msg);
}
˜>

 Regards,
Toivo



Message Edited by toivo on 06-14-2008 04:09 AM
chuckdubdubchuckdubdub
So I'm trying out this curl code, and from what I see it really should work, but am not getting any test records to appear in our account.  When I echo $curl_result I'm just getting a "1".  Are there any security options in SF that need to be enabled to allow this?

Thanks,

Chuck  

werewolfwerewolf
You probably have to whitelist the IP address range of your PHP servers.