How to change Email To address dynamically in contact form 7 based on form data in wordpress

while user submit contact form using contact form 7 , you need to get submitted data to change to address depend on submitted data.
For get submitted data you need below hook

add_action("wpcf7_before_send_mail", "wpcf7_do_something");

by this hook you can get submitted data
function wpcf7_do_something ($WPCF7_ContactForm) {

 $submission = WPCF7_Submission::get_instance();
 $data =&$submission->get_posted_data();  // $data variable is array of data
// do something as you need

}

Also you need one filter hook for change to address
below filter hook is used for change mail components
add_filter( 'wpcf7_mail_components', 'mycustom_wpcf7_mail_components' );

function mycustom_wpcf7_mail_components($components){
  
    // do somthing here and return $components
    return $components;
}

Comments

Popular posts from this blog

How to add a custom sorting or order by option on category archive or product archive page in woocommerce wordpress

How to create a custom wp_list_table and bulk action in wordpress

How to add image option in nav menu in wordpress