Title: WPForms Lite: Dynamic email routing
Last modified: May 12, 2026

---

# WPForms Lite: Dynamic email routing

 *  Resolved [nativebreed](https://wordpress.org/support/users/nativebreed/)
 * (@nativebreed)
 * [4 days, 8 hours ago](https://wordpress.org/support/topic/wpforms-lite-13/)
 * 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.
    -  This topic was modified 4 days, 8 hours ago by [nativebreed](https://wordpress.org/support/users/nativebreed/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [nativebreed](https://wordpress.org/support/users/nativebreed/)
 * (@nativebreed)
 * [3 days, 10 hours ago](https://wordpress.org/support/topic/wpforms-lite-13/#post-18907045)
 * Issue resolved. The issue was that my function was returning a string instead
   of an array.
 * Below is the final working code for anyone that needs it.
 * BTW, I also added, in the final version, an option to set notification_id to 
   apply the routing to – I don’t think this is not necessary – but ….
 *     ```
       define( 'MYFC_FORM_ID', 1 );
       define( 'MYFC_SELECT_FIELD_ID',3 );
       define( 'MYFC_DEFAULT_NOTI_EMAIL', 'c@test.com' );
   
       // Optional: set to an integer to restrict email routing to one specific notification. Leave undefined (or set to 0) to apply routing to ALL notifications on the form.
       define( 'MYFC_NOTIFICATION_ID', 1 );
   
       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;
           } 
           if ( defined( 'MYFC_NOTIFICATION_ID' ) && (int) MYFC_NOTIFICATION_ID !== 0 ) {
               if ( (int) $notification_id !== (int) MYFC_NOTIFICATION_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'] = array( $routed_email );
           return $email;
       }
       ```
   
 *  Plugin Support [Amjad Ali](https://wordpress.org/support/users/amjadali688/)
 * (@amjadali688)
 * [2 days, 7 hours ago](https://wordpress.org/support/topic/wpforms-lite-13/#post-18908201)
 * Hi [@nativebreed](https://wordpress.org/support/users/nativebreed/) ,
 * That’s great to hear. Thanks for coming back and sharing the solution!
 * I’m glad you were able to track down the issue and get it working.
 * Your final code and explanation will definitely be helpful for others who may
   run into the same situation.
 * Thanks again for sharing your solution with the community!

Viewing 2 replies - 1 through 2 (of 2 total)

You must be [logged in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fwpforms-lite-13%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * ![](https://ps.w.org/wpforms-lite/assets/icon.svg?rev=3254748)
 * [WPForms - Easy Form Builder for WordPress - Contact Forms, Payment Forms, Surveys, & More](https://wordpress.org/plugins/wpforms-lite/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wpforms-lite/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wpforms-lite/)
 * [Active Topics](https://wordpress.org/support/plugin/wpforms-lite/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wpforms-lite/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wpforms-lite/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Amjad Ali](https://wordpress.org/support/users/amjadali688/)
 * Last activity: [2 days, 7 hours ago](https://wordpress.org/support/topic/wpforms-lite-13/#post-18908201)
 * Status: resolved