Contact Form 7 wpcf7_mail_sent function not working – can’t capture posted data

Contact Form 7 wpcf7_mail_sent function not working – can’t capture posted data

So I recently came across a problem, I have been using a script for a couple of months that allows me to capture Contact Form 7 data and manipulate it for anything from dynamic post creation to integrating with data capture API’s.

The recent Contact Form 7 version 3.9 no longer contains the posted_data array within the wpcf7_mail_sent function, the is however a simple way to get around this issue.

So you probably currently have something similar to this:

add_action( 'wpcf7_mail_sent', 'your_wpcf7_mail_sent_function' );
 
function your_wpcf7_mail_sent_function( $contact_form ) {
    
    $posted_data = $contact_form->posted_data;
     
    
}

You can fix your posted data by simply changing that function to the following:

add_action( 'wpcf7_mail_sent', 'your_wpcf7_mail_sent_function' );
 
function your_wpcf7_mail_sent_function( $contact_form ) {
    
    $submission = WPCF7_Submission::get_instance();
  
    if ( $submission ) {
    	$posted_data = $submission->get_posted_data();
    }
     
    
}

Thats it! thats how you fix posted_data in the Contact Form 7 wpcf7_mail_sent function – let me know how you get on in the comments and remember to share this post!

Menu Title