WPForms Lite: Dynamic email routing
-
I have written the code below to change form notification email based on the option selected in a field. I have debugged the code and I can see from a log file that the email returned by the function changes based on the option selected. Why is WPForm not sending to the selected email?
Please help.
define( 'MYFC_FORM_ID', 1 ); define( 'MYFC_SELECT_FIELD_ID',3 ); define( 'MYFC_DEFAULT_NOTI_EMAIL', 'c@test.com' ); function myfc_get_email_routes() { return array( 'Text A' => 'a@test.com', 'Text B' => 'b@test.com', ); } add_filter( 'wpforms_entry_email_atts', 'myfc_dynamic_email_routing', 10, 5 ); function myfc_dynamic_email_routing( $email, $fields, $entry, $form_data, $notification_id ) { if ( (int) $form_data['id'] !== MYFC_FORM_ID ) { return $email; } $selected = isset( $fields[ MYFC_SELECT_FIELD_ID ]['value'] ) ? trim( $fields[ MYFC_SELECT_FIELD_ID ]['value'] ) : ''; $routes = myfc_get_email_routes(); $routed_email = MYFC_DEFAULT_NOTI_EMAIL; if ( isset( $routes[ $selected ] ) ) { $routed_email = $routes[ $selected ]; } $email['address'] = $routed_email; return $email; }Thank you.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.