view my SEO resume
Las Vegas SEO & Marketing Director

Capturing Salesforce (web-to-lead) Leads with PHP

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 “”. 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 “”, 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:

<?php $to = ''; 
$subject = 'new lead from website'; 
$message = "A lead has been generated from a page on the website, information is
 below.\n\nSalutation: $salutation\nFirst Name: $first_name\nLast Name: $last_name
\nTitle: $title\nCompany: $company\nPhone: $phone\nMobile: $mobile\nFax: $fax\n
Email: $email\n\nAddress: $street\n$city, $state $zip";
$headers = "From:"; $mail_sent = @mail( $to, $subject, 
$message, $headers ); ?>

After the email is sent the next part of the script is run that uses Javascript

<form id="salesforce_submit" name="salesforce_submit" action="" method="post">
<input name="retURL" type="hidden" value="" />
<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; ?>">

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.

Leave a Reply

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

I design with an eye towards the aesthetic and I approach every project by asking "what's the best way to attract the most qualified visitors?" Every project I complete follows web standards and best practices for ensuring eventual top rankings for relevant keyword terms. Ask me about my las vegas seo, boca raton seo and los angeles seo services.
read more

Latest from Flickr


Steffan Haeberle
9047 W Torino Ave
Las Vegas, NV 89148
Twitter: steffanlv
Facebook: steffan.haeberle
LinkedIn: steffanh

Latest Video