Contact Form (Multiple Addresses)

Good Day I would like to find out if there is a way I could create a contact form that you can choose which department to contact (basically email address).

So that whichever department they choose, lets say “orders” it would go to "orders@mydomain.com when they send the email.

A bar that they click and choose an email address to contact but instead of email it says (example : Orders | Sales | Support )

I added picture below for example. Not these names though.

1 Like

Hi Asher,

You can use the selected value from the dropdown to determine the destination email address. Something like this:

let email = "";
let sel = $w("#dropdown").selectedIndex;
if(sel === 0) {
    email = "orders@company.com";
}
else if(sel === 1) {
    email = "sales@company.com";
}
else if(sel === 2) {
    email = "support@company.com";
}
else {
    email = "admin@company.com";
}

Then just send the email variable to the send email function which will use it as the destination email.

Good luck,

Yisrael

Thanks I think I completed it. Hoping it works now :stuck_out_tongue:

Hello. I’m trying to do this on my contact form. How does one do this:
“…send the email variable to the send email function which will use it as the destination email.”

That means you need to send the email from the page to the backend function so that it can use it during the API call

@shantanukumar847 Thanks but I don’t have a clue how to do that. I’m quite new to WixCode and definitely not a programmer by trade. Can you give more details?

@shellyryder A gentle warning: What you want to do will be a bit challenging for a beginning coder.

I would suggest visiting the following sites for information on programming in Wix Code and Javascript:
https://support.wix.com/en/wix-code/wix-code-basics
https://www.w3schools.com/js/default.asp
https://javascript.info

Also, play with the examples:
https://support.wix.com/en/article/wix-code-index-of-examples
https://www.wix.com/code/home/examples
https://www.grampsworkbench.com/examples

We’re always here to help get you pointed in the right direction.

You may also want to check out the WixArena - it’s a hub where you can look for Wix Code (and other) experts for hire.

Hello. I tried this code and it did not work for me. I am not sure what I missed, the function works however, all of the categories are still sending to the one email connected to the account.

Here is the code I used:
$w.onReady( function () {
let email = “”;
let sel = $w(“#dropdown1”).selectedIndex;
if (sel === 0) {
email = “custom email”;
}
else if (sel === 1) {
email = “custom email”;
}
else if (sel === 2) {
email = “custom email”;
}
else if (sel === 3) {
email = “custom email”;
}
else if (sel === 4) {
email = “custom email”;
}
else if (sel === 5) {
email = “custom email”;
}
else {
email = “custom admin email”;
}
});

I am using a 3 form fields: Name, Email, and a dropdown menu with the specific area for example:
1 above = Awards ; 2 above = Finance ; etc,.

@yisrael-wix Seems like it would have been easier to just tell me what to do. Pouring through all of those links would take hours and hours. Aren’t I mostly there?

@shellyryder “Mostly there” with what? You don’t have any code.

The post above (marked as Top Comment) illustrates how to get the address you want. To send the email itself, see the example: Send Email with SendGrid NPM Interface which uses the SendGrid NPM library.

To send emails with different options (destination, body, etc), see the example:
Send Email with SendGrid NPM Interface which uses the SendGrid NPM library.

@yisrael-wix Thank You :slight_smile:

@yisrael-wix I’m trying to do this exact same thing and this is pretty unclear to me. I’m a developer so the code syntax isn’t the issue. What I don’t understand is where to place the code you mentioned above so that it is called when the user hits submit. I’m assuming we don’t just drop it into the page code onReady function.

Can you clarify that please? Is using sendgrid required in order to have a dropdown change the to-address? If not where in the fix interface do do what you describe here:

“…send the email variable to the send email function which will use it as the destination email.”

The code could be placed in the onChange() event handler for the dropdown. The selected value would then be used to call the send email function. It all depends on what you are doing and what your code looks like.

@Yisrael (Wix) Thanks for the code and the help. It seems pretty clear to me, but I’m missing something…
I always got a console error in the editor: " parsing error: unexpected token ". I guess that is because I haven’t applied the second part of your tutorial which says: " just send the email variable to the send email function which will use it as the destination email".
I don’t think I need to install the NPM library or other modules, this is fairly simple and straight forward, just to options, no customized subject or else.

I just have to options in the drop down so it seems very straight forward but I guess I have to declare the emails that I will use as variables or something? Please help with the part missing… For the moment the code is like this:

import wixWindow from 'wix-window';

$w.onReady(function () {
let email = "";
let sel = $w("#dropdown1").selectedIndex;
if(sel === 1) {
    email = "sales@xxx.com"sales@xxx.com";
}
else if(sel === 2) {
    email = "realestate@xxx.com"realestate@xxx.com";
}
});

Did you try loading the example template in the editor, and setting it up with your email account information? The example shows exactly what you need to do. Once you have the example working you can use the code and screens in your own site.

Hello,
I wonder if this meanwhile is also possible without using SendGrid or other 3rd party send services?

@yisrael-wix please show me the code to use wix instead of sandgrid. THANKS

@yisrael-wix would you be able to elaborate little more on this? could you include the full steps? I’ve been searching and seeing bits of pieces. Thank you!!

Several clients have asked me for this feature. How can we create a request to send form messages to different emails according to a chosen variable, and vote for this feature?

1 Like