Use select field value in the CC addresses admin email notification field.

I would like send an email notification to a select field value.

  • Ash
    • WordPress Hacker

    Hello Bradley

    If you click on the CC field, then a select drop down list appears which shows all the field names. You can select the email address field from there which can be used as cc address. Here is a screenshot:

    Let me know if that works for you. Have a nice day!

    Cheers,
    Ash

  • Bradley
    • Flash Drive

    Hello. I just wanted to let you know that this solution does not work and we have already tried with the other chat support. The reason why it will not work is because I am using dropdown field instead of email field.

    if you check the form on this page:
    https://meridianteam.com/contact/

    There is a field name "whom you would like to contact"

    So when someone submitted the form, I wanted the one they chose on that dropdown to be where the notifications will be sent. Please try and check on this one so I can solve my problem.

  • Bradley
    • Flash Drive

    Hello. I just wanted to let you know that the Support Access have been granted.

    Please remember that we are trying to make work is the form on this page:
    https://meridianteam.com/contact/
    so when someone choose Whom would you like to contact field, the notification email will be sent to that email chosen. That is what we wanted to happen.

    Please also remember that site is under a multisite and the internal link is https://meridianteam.bradcable4.com/

    Please let me know if there is anything else that I can help you with so we can finish up and resolve this issue.

    Thanks,

  • Ash
    • WordPress Hacker

    Hello Bradley

    I am sorry for the delay. We process the threads based on the queue. When you post multiple replies it pushes your thread to the bottom of the queue.

    Okay, in your case, you will need an extra email field. So, the select dropdown field is original email field and there will an extra email field. Please follow the link: http://recordit.co/fVDx7OOcPJ

    Make sure to use the exact class names that I shown. Now use this code:

    add_action( 'wp_footer', function() {
    	?>
    	<style>
    		.hidden-email{display: none;}
    	</style>
    	<script>
    		jQuery(function($){
    			$(document).on( 'change', '.orig-email select', function() {
    				var val = $(this).val();
    				$( '.hidden-email input' ).val(val);
    			} );
    		});
    	</script>
    	<?php
    } );

    You can use this code in your child theme's functions.php if the theme is not changed. Otherwise mu-plugin is the best option. To create a mu-plugin, go to wp-content/mu-plugins folder. If there is no mu-plugins folder then, create one. Now, inside the mu-plugins folder create file with name anything.php (make sure file extension is .php). Now start with a <?php tag and then put the above code.

    And then set the email recipient like I suggested in this reply: https://premium.wpmudev.org/forums/topic/use-select-field-value-in-the-cc-addresses-admin-email-notification-field#post-1407800

    Let us know if that works for you. Have a nice day!

    Cheers,
    Ash

  • Bradley
    • Flash Drive

    Hello. I just wanted to update you about this. We already followed the instruction that is sent by the support last time. followed it step by step but unfortunately, still it is not working.. You can't choose on the email notification that field that we wanted the notification to be sent. Did you try it on your end?

  • Nithin
    • Support Wizard

    Hi Bradley,

    Sorry for the delay in getting back to you, we reply to tickets based on queue order so all the member's thread gets looked upon easily.

    Since support access to your website is no longer enabled, I wasn't able to check the default configuration in your form.

    There's a workaround using forminator_custom_form_mail_admin_recipients hook which works finen when tested.

    However, to give the exact code, I'll need to check how the options are added in your select field. I'm providing the code based on how I have tested in my test server, please make the changes as shown in the following screenshot:

    Where the value field added as seen in the above screenshot should be a unique keyword. Once done, please add the following code as a mu-plugins:

    <?php
    
    add_filter( 'forminator_custom_form_mail_admin_recipients', function( $recipients, $custom_form, $data, $entry ){
    
        $check_field = 'select-1';
        $emails = array(
            'emailone' => array(
                'example@gmail.com'
            ),
            'emailtwo' => array(
                'youremali@gmail.com'
            ),
    	'emailthree' => array(
    	    'test@gmail.com'
    	)
        );
    
        $check_value = $data[ $check_field ];
    
        if ( isset( $emails[ $check_value ] ) ) {
            return $emails[ $check_value ];
        }
    
        return $recipients;
    
    }, 20, 4 );

    In the above code, the following section is where the emails and the unique value field should be added:

    $emails = array(
            'emailone' => array(
                'example@gmail.com'
            ),
            'emailtwo' => array(
                'youremali@gmail.com'
            ),
    	'emailthree' => array(
    	    'test@gmail.com'
    	)
        );

    So if a new value is added in the select field, the above code will get updated as follows:

    $emails = array(
            'emailone' => array(
                'example@gmail.com'
            ),
            'emailtwo' => array(
                'youremali@gmail.com'
            ),
    	'emailthree' => array(
    	    'test@gmail.com'
    	),
    	'emailfour' => array(
    		'abc@gmail.com'
    	)
        );

    You can implement the above code via mu-plugins as mentioned in the following article:
    https://premium.wpmudev.org/manuals/wpmu-manual-2/using-mu-plugins/

    I can confirm the above code works fine when tested in my system, and sends emails only to the email selected value in the select box.

    If you still have issues or queries with running the code then please enable support access so that I could give an exact code if needed based on the values what you have added.

    You can grant access from WPMU DEV > Support > Support Access > Grant Access, or check this manual: https://premium.wpmudev.org/docs/getting-started/getting-support/#chapter-5

    Regards,
    Nithin

  • Bradley
    • Flash Drive

    Hello. Unfortunately no. Those you and Nithin have sent does not work for us. the support is enabled. can you please go and check and show me it's working fine or if you can try it and see it working then please send us step by step instruction on what to do so we can do on other sites. Thank you.

  • Nithin
    • Support Wizard

    Hi Bradley,

    Could I know on which form did you test it out? I checked the "Contact Us" form, and I don't see any of the changes being applied as mentioned in the given instructions in the previous reply.

    I went ahead and created a copy of the Contact Us form, so I could edit it further without hampering the live contact form and have made the changes as seen in the previously shared screenshot.

    Could you please add the following code as a mu-plugins, and then check whether the duplicate contact form is working fine:

    <?php
    
    add_filter( 'forminator_custom_form_mail_admin_recipients', function( $recipients, $custom_form, $data, $entry ){
    
        $check_field = 'select-1';
        $emails = array(
            'emailone' => array(
                'david.hansen@lpl.com'
            ),
            'emailtwo' => array(
                'tanya.mathews@lpl.com'
            ),
    	'emailthree' => array(
    	    'richard.mower@lpl.com'
    	),
    
    	'emailfour' => array(
    	    'richard.weintraub@lpl.com'
    	),
    
    	'emailfive' => array(
    	    'lexy.schmidt@lpl.com'
    	),
    
    	'emailsix' => array(
    	    'mdedoyo@bradcable.com'
    	),
    
    	'emailseven => array(
    	    'cssrexajay@gmail.com'
    	)
    
        );
    
        $check_value = $data[ $check_field ];
    
        if ( isset( $emails[ $check_value ] ) ) {
            return $emails[ $check_value ];
        }
    
        return $recipients;
    
    }, 20, 4 );

    I have already created a new test contact page where the duplicate contact form is added:
    https://meridianteam.com/test-contact/

    Please do add the above code as a mu-plugins, and then check whether the duplicator contact form works. If yes, you just have to copy the similar options added to the Select field to the live Contact Form page too.

    Please let us know how that goes. Have a nice day ahead.

    Regards,
    Nithin

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.