我花了几个小时寻找解决方案,但没有任何效果,我尝试了所有推荐的解决方案,例如http://daddyanalytics.com/integrating-contact-form-7-and-salesforce/和http://www.alexhager.at/how- to-integrate-salesforce-in-contact-form-7/
我解决了这个问题:)
我也试过插件https://wordpress.org/plugins/forms-3rdparty-integration/
但是没有任何效果,然后在搜索过程中有人发布了带有钩子 wpcf7_mail_components 的解决方案。当我使用代码时,代码真的很有效,这要感谢那个人。我现在不记得链接了。但是,我的目标是让 wpcf7_before_send_mail 可调用和可访问。因为上述建议从未调用过它。
然后我介绍了最后两个参数,即
add_action('wpcf7_before_send_mail', 'my_conversion', 10, 1); //this will call the hook
add_action('wpcf7_before_send_mail', 'my_conversion'); //not calling the hook for me
add_action('wpcf7_before_send_mail', 'my_conversion', 10); //also not calling the hook for me
如果能解决您的问题,请点赞。
所以这里是完整的解决方案:
add_action('wpcf7_before_send_mail', 'my_conversion', 10, 1);
function my_conversion($cf7) {
$email = $cf7->posted_data["email"];
$name = $cf7->posted_data["name"];
$phone = $cf7->posted_data["phone"];
$business_type = $cf7->posted_data["business-type"];
$no_stations = $cf7->posted_data["number-of-stations"];
$lead_source = $cf7->title;
$post_items[] = 'oid=<YOUR-SALES-FORCE-ID>';
$post_items[] = 'name=' . $name;
$post_items[] = 'email=' . $email;
$post_items[] = 'phone=' . $phone;
$post_items[] = 'business_type=' . $business_type;
$post_items[] = 'no_of_stations=' . $no_stations;
$post_items[] = 'lead_source=' . $lead_source;
if (!empty($name) && !empty($phone) && !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
}
}