In wordpress Contact Form Plugin version 3.9 onwards the structure of the plugin changed, and this has had a major impact on the wpcf7_before_send_mail() hook usage. If you now want to access the email posted data – keys and post value, below shows the old method and then the new method. Hope it helps someone. Note that the posted_data object property no longer exists.
Old Method:
add_action("wpcf7_before_send_mail", "my_function"); function my_function(&$cf7) { foreach ($cf7->posted_data as $keyval => $posted) { // use $keyval and $posted as elements in email forms } }
New Method:
add_action("wpcf7_before_send_mail", "my_function"); function my_function($cf7) { $submission = WPCF7_Submission::get_instance(); if($submission) { $posted_data = $submission->get_posted_data(); foreach ($posted_data as $keyval => $posted) { // use $keyval and $posted as elements in email forms } } }