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:
httpdocs / wp-content / plugins / contact-form-7 / includes / functions.php
HTML CODE:
[HTML]
[text* your-firstname ]
[text* your-lastname ]
[email* your-email ]
[text your-phone ]
[/HTML]
PHP CODE: httpdocs / wp-content / plugins / contact-form-7 / includes / functions.php
[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
}
}
[/PHP]