contact form 7 wordpress plugin not working properly

I am using contact form 7 wordpress plugin for one of website and facing problem to adding action after sending mail.

I want to call some CRM Api when data submitted by the user and also sent mail to admin so i have tried following way.

I added action and function to function.php

1) add_action('init', create_function('', 'add_action("wpcf7_admin_after_mail", "leads_integration_wp_cf7");'));

function leads_integration_wp_cf7($cf7 ) {

$title = $contact_form->title;
$submission = WPCF7_Submission::get_instance();

if($submission)
{
    $posted_data = $submission->get_posted_data();
    //using curl make request here
}

}

So using this way i got mail but i am thinking my function(leads_integration_wp_cf7) did not called and i did not get entry in CRM.

2)

add_action('wpcf7_before_send_mail', 'leads_integration_wp_cf7');

using this way i made successfully request to CRM but mail sending stop.on a form page ajax preloader loading,loading, and not redirect on url.

Anybody face this issue i am new in wordpress.


Solution 1:

The action wpcf7_admin_after_mail is called in edit-contact-form.php file and it is used for form control ui purpose so it will not be helpful for this case.

The action wpcf7_before_send_mail is correct for doing some task when contact form is posted and email is sent, can you confirm that mail is working properly if this action hook is not applied?

Also try renaming the param $cf7 to $contact_form

function leads_integration_wp_cf7($cf7) {

To

function leads_integration_wp_cf7($contact_form) {