Integrate WordPress Contact Form 7 and Salesforce Web to Lead

we need to write the curl (php) funictionality in functions.php file in wordpress server. login to your ftp server and you can find the file name called functions.php in your wp-includes folder with following path:

SFDC_WordPress blue-plus ContactForm7

httpdocs / wp-content / plugins / contact-form-7 / includes / functions.php

HTML CODE:

<label>First Name <span>*</span></label>[text* your-firstname ]
<label>Last Name <span>*</span></label>[text* your-lastname ]
<label>Email <span>*</span></label>[email* your-email ]
<label>Phone</label>[text your-phone ]

PHP CODE: httpdocs / wp-content / plugins / contact-form-7 / includes / functions.php

add_action( 'wpcf7_before_send_mail', 'leadFromWebtoSFDC' );
function leadFromWebtoSFDC( $cf7 ) {
$email = $cf7->posted_data["your-email"];
$first_nameĀ  = $cf7->posted_data["your-firstname"];
$last_nameĀ  = $cf7->posted_data["your-lastname"];
$phone = $cf7->posted_data["your-phone"];

$post_items[] = 'oid=<YOU_SALESFORCE_OID>';
$post_items[] = 'first_name=' . $first_name;
$post_items[] = 'last_name=' . $last_name;
$post_items[] = 'email=' . $email;
$post_items[] = 'phone=' . $phone;

if(!empty($first_name) && !empty($last_name) && !empty($email) ) {
$post_string = implode ('&', $post_items);
// Create a new cURL resource
$ch = curl_init();

if (curl_error($ch) != "") {
// error handling
}

$con_url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
curl_setopt($ch, CURLOPT_URL, $con_url);
// Set the method to POST
curl_setopt($ch, CURLOPT_POST, 1);
// Pass POST data
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_string);
curl_exec($ch); // Post to Salesforce
curl_close($ch); // close cURL resource
}
}

Written by 

I am Sakthivel Madesh, a certified Salesforce Advanced Developer & Administrator working on Salesforce Technology since 2011. I am currently working in Techforce Services as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 15x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead 5x Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply

Your email address will not be published. Required fields are marked *

*