How do you email a salesforce lead upon web-to-lead creation?
One of my clients asked for the ability to email Salesforce leads at the time of lead creation from a form on our website. This sounded simple, but I discovered was far from it.
Salesforce has the capability for generating leads from an online form on a website called web-to-lead. This basic form capturing ability sends the forms in the lead to Salesforce via a POST of the variables. The URL for the ACTION field in the form is typically something like “http:// www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8”. What happens once the form is sent to that URL is the form data is processed and a retURL is used to return the browser to the website.
Unfortunately, none of the variables in the POST are returned, basically meaning all the form’s information is lost.
The solution?
There might be easier ways to handle capturing the FORM data on the server before sending it to Salesforce, however this is the solution I came up with.
Instead of sending the lead off directly to “http:// www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8”, I instead sent it to another page on my client’s server via POST. I wasn’t able to use cURL like some people are able to (check out Paul West’s solution using cURL). So, since I did have PHP to use I dumped all the form variables into PHP variables. Then, I sent the email using:
After the email is sent the next part of the script is run that uses Javascript
<script language="JavaScript">
setTimeout('document.salesforce_submit.submit()',3);
</script>
<form id="salesforce_submit" name="salesforce_submit" action=" http:// www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="post">
<input name="retURL" type="hidden" value="http://www.website.com?page=returnurl">
<input type="hidden" id="salutation" name="salutation" value="<?php echo $salutation; ?>">
<input type="hidden" id="first_name" name="first_name" value="<?php echo $first_name; ?>">
<input type="hidden" id="last_name" name="last_name" value="<?php echo $last_name; ?>">
<input type="hidden" id="title" name="title" value="<?php echo $title; ?>">
<input type="hidden" id="lead_source" name="lead_source" value="Web - ISA">
<input type="hidden" name="oid" value="">
<input type="hidden" id="company" name="company" value="<?php echo $company; ?>">
<input type="hidden" id="phone" name="phone" value="<?php echo $phone; ?>">
<input type="hidden" id="mobile" name="mobile" value="<?php echo $mobile; ?>">
<input type="hidden" id="fax" name="fax" value="<?php echo $fax; ?>">
<input type="hidden" id="email" name="email" value="<?php echo $email; ?>">
<input type="hidden" id="street" name="street" value="<?php echo $street; ?>">
<input type="hidden" id="city" name="city" value="<?php echo $city; ?>">
<input type="hidden" id="state" name="state" value="<?php echo $state; ?>">
<input type="hidden" id="zip" name="zip" value="<?php echo $zip; ?>">
</form>
The code above submits the form via the Javascript call. It relies on a short delay and then once the form is sent the page is redirected to another page using retURL. Pretty straightforward. There might be a more elequant way of doing this. I know many people online were looking for a way to do this in order to take FORM info and add it to their database or session variables. I hope this helps and if anyone knows of a better way of doing this, please feel free to post a comment.