ソリューションの検索に何時間も費やしましたが、何も機能しませんでした。たとえば、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を呼び出し可能でアクセス可能にすることでした。上記の推奨事項では呼び出されなかったため。
次に、最後の2つのパラメーターを紹介しました。
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
}
}