Skip to content

Instantly share code, notes, and snippets.

@Minasokoni
Created October 10, 2016 17:21
Show Gist options
  • Save Minasokoni/de39f790df49534a4ed9b2d670fd5fc4 to your computer and use it in GitHub Desktop.
Save Minasokoni/de39f790df49534a4ed9b2d670fd5fc4 to your computer and use it in GitHub Desktop.
contact form 7 - salesforce
add_action( 'wpcf7_before_send_mail', 'my_conversion' );
function my_conversion( $cf7 )
{
$email = $cf7->posted_data["your-email"];
$first_name = $cf7->posted_data["first-name"];
$last_name = $cf7->posted_data["last-name"];
$phone = $cf7->posted_data["your-phone"];
$where = $cf7->posted_data["text-wheredoyouwanttogo"];
$when = $cf7->posted_data["your-whendoyouwanttogo"];
$referred = $cf7->posted_data["your-referredby"];
$msg = $cf7->posted_data["your-message"];
$newsletter = $cf7->posted_data["mc4wp_checkbox"];
$post_items[] = 'oid=00Do0000000eOS9';
$post_items[] = 'first_name=' . $first_name;
$post_items[] = 'last_name=' . $last_name;
$post_items[] = 'email=' . $email;
$post_items[] = 'phone=' . $phone;
$post_items[] = '00No000000EG3QJ='.$where;
$post_items[] = '00No000000EG3QO='.$when;
$post_items[] = '00No000000EG3QT='.$referred;
$post_items[] = '00No000000EG3QY='.$msg;
$post_items[] = '00No000000EG3Qd='.$newsletter;
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
}
print_r($post_items);
$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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment