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;
}
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
Post a Comment