Skip Navigation

[Closed] How to assign Contact Form to send messages to different emails addresses

This support ticket is created 3 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 3 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#1920921

Tell us what you are trying to do?

I want to create a Contact form with different options to select from(which sends message to different email addresses). This will be: employment(A), housing(B), benefits(C), EU Settlement Scheme(D) and Other(E)]

The thing is that the messages have to go to different email depending what language

eg. English version A,B,C - goes to Email 1
English version D,E - goes to Email 2
Spanish version A,B,C - goes to Email 3
Spanish Version D,E - goes to Email 1
Polish Version A,B,C - goes to Email 4
Polish Version D,E - goes to Email 1

So it would be something like it is now

hidden link

+ drop down with the option to what department the message should go to depending of the language

Could you tell me if I should use Toolset Forms for this?

What should I start with?

Thanks

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#1920993
Screen Shot 2021-01-27 at 2.05.21 PM.png

Hello, there's nothing exactly like this built-in to Forms notifications, but it's possible with some custom code. We offer a PHP API you can use to manipulate the email recipients for any notification. You can see the documentation available here: https://toolset.com/documentation/programmer-reference/cred-api/#cred_notification_recipients. Normally you would set the notification to send to some default address like noreply@yoursite.com, and allow the API hook to add a CC email address. A simple example that CC's a recipient to a notification called "Content submitted" (screenshot attached):

add_filter('cred_notification_recipients', 'modify_recipients', 10, 4);
function modify_recipients($recipients, $notification, $form_id, $post_id) {
     $notification_name = "Content submitted";
     $cc_email = "log@emailaddress.com";
  
    // Only add this CC to the notification with name defined in notification_name variable above
    if ( isset($notification['name']) && $notification_name == $notification['name'] ) {
 
        // Add a CC to cc_email address defined above
        $recipients[] = array(
            'to'        =>  'cc',
            'address'   => $cc_email,
            'name'      =>  '',
            'lastname'  =>  ''
            );
    }
          
    return $recipients;
}

See in the screenshot this notification is called "Content submitted", and the code is set up so that the CC email is only added to this specific notification. You can use this code as a guide for setting up your own custom code, with some modifications.

It sounds like you need to determine the email address based on two variables:
1. The language of the page where the Form was submitted
2. The selected value in a select field. I'm not clear from your description if this is a generic field or a custom field. I'll assume it's a generic field.

To determine the language of the page where the Form was submitted, it might be simplest to add a generic hidden field to the Form, and set the default value using the current page's post ID. Here's a code snippet you could use in the expert Form builder to add such a generic hidden field:

[cred_generic_field type='hidden' field='current-post-id']
{
"default":"[wpv-post-id item="$current_page"]"
}
[/cred_generic_field]

Then in the PHP code, you can access the current post ID in the $_POST superglobal:

$current_post_id = $_POST['current-post-id'];

The current post ID for each language will be different, so you can use that ID to determine the language of the page where the Form was submitted. If you're not sure of the IDs for each language, I can help you figure those out once you set up the generic hidden field in the Form and have that Form displayed on the front-end of your site in all the different language posts.

To access the selected value of a generic field in the PHP code, you can again check in the $_POST superglobal:

$selected_option = $_POST['generic-field-slug'];

Change generic-field-slug to match the slug of the generic select field, and the variable will contain the selected option value.

Then you'll need a series of conditionals or a custom function or hash to determine the proper email address based on the post ID and selected field.

#1921795

Hi

Thanks for explanation, Hopefully I will be able to put it together, but for sure I will have some questions 🙂

However, there is an issue which I posted here

https://toolset.com/forums/topic/theres-an-issue-when-creating-new-post-form-plugin-cmsmasters-content-composer/

Cheers

#1921833

Okay we can discuss that problem in the other ticket.

The topic ‘[Closed] How to assign Contact Form to send messages to different emails addresses’ is closed to new replies.