I am working on a site with several forms created using Contact Form 7. For one of these forms, I am passing variables that I collected using a hidden input field in the fo
I was using Dinesh's answer, but it stopped working for me. Instead, I am now checking for a field that is unique to the form I'm submitting:
add_action( 'wpcf7_before_send_mail', 'wpcf7_add_text_to_mail_body' );
function wpcf7_add_text_to_mail_body($contact_form){
$submission = WPCF7_Submission::get_instance();
$posted_data = $submission->get_posted_data();
if( !empty($posted_data["dealer_email"])){ //use a field unique to your form
$email = trim($posted_data["dealer_email"]);
// more custom stuff here
}
}
Be sure to have at least one unique form name in each of your forms that you can use to do this. It might still be possible to get the form ID from $contact_form via a function, but this worked and I was content with the result.