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.
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.”
@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?
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 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.
@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?