# Wix Code - Sending form submission to three recipients

**URL:** <https://forum.wixstudio.com/t/wix-code-sending-form-submission-to-three-recipients/33889>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [June 25, 2018, 6:03pm UTC](https://forum.wixstudio.com/t/wix-code-sending-form-submission-to-three-recipients/33889 "2018-06-25T18:03:31Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![jessicasilvers28](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jessicasilvers28/32/3932_2.png) [@jessicasilvers28](https://forum.wixstudio.com/u/jessicasilvers28)\
**Post date:** [June 25, 2018, 6:03pm UTC](https://forum.wixstudio.com/t/wix-code-sending-form-submission-to-three-recipients/33889/1 "2018-06-25T18:03:31Z")

</div>

Hi! I am a designer, who has a little bit of knowlege with code. I have followed all the steps in the Wix walk-through and followed a youtube video to set-up an automatic email to be sent to my clients when someone fills out their form and it works SUCCESSFULLY. I am using SendGrid as recommended in the Wix article (see below).

**The problem** is that I need this form to send out an email to **THREE different email addresses: 1 email** when someone fills out the form, and **2 emails** to two different people on our team including the info from the form.

Below are screen shots of the code I currently have, and the links to the article/video that helped me set everything up successfully.

Thanks in advance for your help!

VIDEO: [https://www.youtube.com/watch?v=bPd7o7hUfGk](https://www.youtube.com/watch?v=bPd7o7hUfGk)  
ARTCILE: [Velo Tutorial: Sending an Email on Form Submission | Help Center | Wix.com](https://support.wix.com/en/article/how-to-send-an-email-on-form-submission)

**SCREENSHOTS**  
**Backend Code .JSW (below)**

 ![](https://us1.discourse-cdn.com/wix/original/3X/6/b/6b41439d9dbdcf1e8921d8a92557d17a8e54559c.png)  
You can see that the recipient is the email address that starts with “emily@”, and when I had copy and pasted another recipient line, I got an error.

**Backend .JS Code (using SendGrid)**

 ![](https://us1.discourse-cdn.com/wix/original/3X/a/f/afe5f1cf69467a06b6e12d30f15694e18b75b7c9.png)  
**On-Page Code**

 ![](https://us1.discourse-cdn.com/wix/original/3X/a/f/af5af1a3a120693cfa90a9ef522ba7fb37fa0ad2.jpeg)

---

<div class="post-metadata">

**Author:** ![jessicasilvers28](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jessicasilvers28/32/3932_2.png) [@jessicasilvers28](https://forum.wixstudio.com/u/jessicasilvers28)\
**Post date:** [June 25, 2018, 7:08pm UTC](https://forum.wixstudio.com/t/wix-code-sending-form-submission-to-three-recipients/33889/2 "2018-06-25T19:08:30Z")

</div>

Code from above, pasted here for easy editing for you:

**WEB MODULE .JSW**  
[//email.jsw](https://email.jsw)  
import {sendWithService} from ‘backend/sendGrid’;  
export function sendEmail(subject, body) {  
const key = “API CODE HERE”;  
const sender = “[osprey@wecaninternational.org](mailto:osprey@wecaninternational.org)”;  
const recipient = “[emily@wecaninternational.org](mailto:emily@wecaninternational.org)”;  
**return** sendWithService(key, sender, recipient, subject, body);  
}  
export function sendEmailWithRecipient(subject, body, recipient) {  
const key = “API CODE HERE”;  
const sender = “[osprey@wecaninternational.org](mailto:osprey@wecaninternational.org)”;  
**return** sendWithService(key, sender, recipient, subject, body);  
}

**WEB MODULE .JS**  
[//sendGrid.js](https://sendGrid.js)  
import {fetch} from ‘wix-fetch’;  
export function sendWithService(key, sender, recipient, subject, body) {  
const url = “[https://api.sendgrid.com/api/mail.send.json](https://api.sendgrid.com/api/mail.send.json)”;  
const headers = {  
“Authorization”: "Bearer " + key,  
“Content-Type”: “application/x-www-form-urlencoded”  
};  
const data = ` from =${sender}&to=${recipient}&subject=${subject}&text=${body}`;  
const request = {  
“method”: “post”,  
“headers”: headers,  
“body”: data  
};  
**return** fetch(url, request)  
.then(response =\> response.json());  
}

**ON PAGE CODE**

import {sendEmail, sendEmailWithRecipient} from ‘backend/email’;

$w.onReady( function () {  
$w(“#dataset1”).onAfterSave(sendFormData);  
});

function sendFormData() {  
const subject = `Thanks **for** joining WECAN, our growing network of Women **for** Climate Justice, ${$w("#input1").value}`;  
const body = `Name: ${$w("#input1").value} \rName: ${$w("#input1").value} \rEmail: ${$w("#input2").value} \rCountry: ${$w("#input3").value} \rOrganization: ${$w("#input4").value} \rComments: ${$w("#textBox1").value} \rOptin1: ${$w("#checkbox1").value} \rOptin2: ${$w("#checkbox2").value} \rOptin3: ${$w("#checkbox3").value}`;  
const recipient = $w(“#input2”).value;

sendEmailWithRecipient(subject, body, recipient)  
.then(response =\> console.log(response));

sendEmail(subject, body)  
.then(response =\> console.log(response));  
}

---

<div class="post-metadata">

**Author:** ![Shan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/shan/32/106059_2.png) [@Shan](https://forum.wixstudio.com/u/Shan)\
**Post date:** [June 25, 2018, 7:09pm UTC](https://forum.wixstudio.com/t/wix-code-sending-form-submission-to-three-recipients/33889/3 "2018-06-25T19:09:02Z")

</div>

Hi Jess,

The following:

- const **subject**

- const **body**

- const **recipient**  
are the ones you need to duplicate such as

- const **subject1**

- const **body1**

- const **recipient1**  
Then send it to the backend modules with your **sendEmail**

Please see an example below:

```javascript
 
function sendFormData() {
 const subject1 = `Booking Confirmation`;
 const body1 = `Hi`;
 const recipient = $w("#input4").value;
 
 const subject2 = `English Client Booking`;
 const body2 = `Hello`;
 
 sendEmailWithRecipient(subject1, body1, recipient)
 .then(response => console.log(response));
 
  sendEmail(subject2, body2)
    .then(response => console.log(response)); 
}

```

You can call them as many times you want using the above example

---

<div class="post-metadata">

**Author:** ![jessicasilvers28](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jessicasilvers28/32/3932_2.png) [@jessicasilvers28](https://forum.wixstudio.com/u/jessicasilvers28)\
**Post date:** [June 25, 2018, 7:11pm UTC](https://forum.wixstudio.com/t/wix-code-sending-form-submission-to-three-recipients/33889/4 "2018-06-25T19:11:06Z")

</div>

Hi Shan!

Thank you! Could please copy and paste the code I sent above your comment to show me where this should go… for instance, not 100% sure which module this code should be placed.

---

<div class="post-metadata">

**Author:** ![jessicasilvers28](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jessicasilvers28/32/3932_2.png) [@jessicasilvers28](https://forum.wixstudio.com/u/jessicasilvers28)\
**Post date:** [June 25, 2018, 7:14pm UTC](https://forum.wixstudio.com/t/wix-code-sending-form-submission-to-three-recipients/33889/5 "2018-06-25T19:14:28Z")

</div>

Or please confirm that this is correct:

**const** subject2 = `Thanks **for** joining WECAN, our growing network of Women **for** Climate Justice, ${$w("#input1").value}`;  
**const** body2 = `Name: ${$w("#input1").value} \rName: ${$w("#input1").value} \rEmail: ${$w("#input2").value} \rCountry: ${$w("#input3").value} \rOrganization: ${$w("#input4").value} \rComments: ${$w("#textBox1").value} \rOptin1: ${$w("#checkbox1").value} \rOptin2: ${$w("#checkbox2").value} \rOptin3: ${$w("#checkbox3").value}`;

sendEmailWithRecipient(subject1, body1, recipient)  
.then(response =\> console.log(response));

sendEmail(subject2, body2)  
.then(response =\> console.log(response));

---

<div class="post-metadata">

**Author:** ![Shan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/shan/32/106059_2.png) [@Shan](https://forum.wixstudio.com/u/Shan)\
**Post date:** [June 25, 2018, 7:43pm UTC](https://forum.wixstudio.com/t/wix-code-sending-form-submission-to-three-recipients/33889/6 "2018-06-25T19:43:06Z")

</div>

Did you mean a total of 3 emails including the Email being sent to the person who is filling the form ?

If thats the case then you need to do this to your **email.jsw**

```javascript
//email.jsw

import {sendWithService} from 'backend/sendGrid';

export function sendEmail(subject, body) {
const key = "";
const sender = "osprey@wecaninternational.org";
const recipient = "emily@wecaninternational.org";
return sendWithService(key, sender, recipient, subject, body);
}

export function sendEmailWithRecipient(subject, body, recipient) {
const key = "";
const sender = "osprey@wecaninternational.org";
return sendWithService(key, sender, recipient, subject, body);
}

//Add the below function
  
export function sendThirdEmail(subject, body) {
const key = "";
const sender = "osprey@wecaninternational.org";
const recipient = "youremailaddress" //enter your email address here
return sendWithService(key, sender, recipient, subject, body);
}

```

And If its the same data then the Page Code will look like this:

```javascript
function sendFormData() {

 const subject = `Thanks for joining WECAN, our growing network of Women for Climate Justice, ${$w("#input1").value}`;
 const body = `Name: ${$w("#input1").value}
    \rName: ${$w("#input1").value}
    \rEmail: ${$w("#input2").value}
    \rCountry: ${$w("#input3").value}
    \rOrganization: ${$w("#input4").value}
    \rComments: ${$w("#textBox1").value}
    \rOptin1: ${$w("#checkbox1").value}
    \rOptin2: ${$w("#checkbox2").value}
    \rOptin3: ${$w("#checkbox3").value}`;
 const recipient = $w("#input2").value;
 
 
  sendEmailWithRecipient(subject, body, recipient)
    .then(response => console.log(response)); 
 
  sendEmail(subject, body)
    .then(response => console.log(response));

  sendThirdEmail(subject, body) 
    .then(response => console.log(response)); 
}

```

Sorry I might have misunderstood your goal initially

---

<div class="post-metadata">

**Author:** ![jessicasilvers28](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jessicasilvers28/32/3932_2.png) [@jessicasilvers28](https://forum.wixstudio.com/u/jessicasilvers28)\
**Post date:** [June 25, 2018, 7:59pm UTC](https://forum.wixstudio.com/t/wix-code-sending-form-submission-to-three-recipients/33889/7 "2018-06-25T19:59:08Z")

</div>

Oh… Thank you!

I will test this code and remove my API from the thread.

---

<div class="post-metadata">

**Author:** ![jessicasilvers28](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jessicasilvers28/32/3932_2.png) [@jessicasilvers28](https://forum.wixstudio.com/u/jessicasilvers28)\
**Post date:** [June 25, 2018, 8:05pm UTC](https://forum.wixstudio.com/t/wix-code-sending-form-submission-to-three-recipients/33889/8 "2018-06-25T20:05:14Z")

</div>

And to answer your question, yes!

Right now, the form sends one to the person who fills out the form, and one to Emily (on our team). I’m trying to get this form to send three emails, 1 to the person who fills out the form, and 2 that are sent to people on our team.

Is there a way to make the form that is sent to the user and the two to our team different? For instance, I’d like the email to say “thanks for joining our team! Someone will reach out to you shortly” and then the form information sent to two people on our team.

---

<div class="post-metadata">

**Author:** ![jessicasilvers28](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jessicasilvers28/32/3932_2.png) [@jessicasilvers28](https://forum.wixstudio.com/u/jessicasilvers28)\
**Post date:** [June 25, 2018, 8:08pm UTC](https://forum.wixstudio.com/t/wix-code-sending-form-submission-to-three-recipients/33889/9 "2018-06-25T20:08:16Z")

</div>

Also, can the body be any size? I can truncate the subject, but I would like the body to say something a little more if possible.

---

<div class="post-metadata">

**Author:** ![Shan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/shan/32/106059_2.png) [@Shan](https://forum.wixstudio.com/u/Shan)\
**Post date:** [June 25, 2018, 8:09pm UTC](https://forum.wixstudio.com/t/wix-code-sending-form-submission-to-three-recipients/33889/10 "2018-06-25T20:09:33Z")

</div>

both my above comments will help you achieve that

you can create 2 different emails with my 1st comment example and send it to multiple people with the example in my 2nd comment

---

<div class="post-metadata">

**Author:** ![jessicasilvers28](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jessicasilvers28/32/3932_2.png) [@jessicasilvers28](https://forum.wixstudio.com/u/jessicasilvers28)\
**Post date:** [June 25, 2018, 8:14pm UTC](https://forum.wixstudio.com/t/wix-code-sending-form-submission-to-three-recipients/33889/11 "2018-06-25T20:14:12Z")

</div>

Thank you so much Shan. Going to test out the code now.  
Will let you know if it works or need more assistance.

---

<div class="post-metadata">

**Author:** ![jessicasilvers28](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jessicasilvers28/32/3932_2.png) [@jessicasilvers28](https://forum.wixstudio.com/u/jessicasilvers28)\
**Post date:** [June 25, 2018, 8:26pm UTC](https://forum.wixstudio.com/t/wix-code-sending-form-submission-to-three-recipients/33889/12 "2018-06-25T20:26:28Z")

</div>

I am having an error with the on-site code:  
It says that it’s not defined. I copy and pasted your .jsw code and added in the other recipient email, so it should be working… right?

 ![](https://us1.discourse-cdn.com/wix/original/3X/b/8/b88be5126977c3f5b1ff8492776c645fc4e28014.png)

---

<div class="post-metadata">

**Author:** ![jessicasilvers28](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jessicasilvers28/32/3932_2.png) [@jessicasilvers28](https://forum.wixstudio.com/u/jessicasilvers28)\
**Post date:** [June 25, 2018, 8:35pm UTC](https://forum.wixstudio.com/t/wix-code-sending-form-submission-to-three-recipients/33889/13 "2018-06-25T20:35:15Z")

</div>

For reference, this is where the form exists: [https://jessrightdesign.wixsite.com/wecan1/join-the-network](https://jessrightdesign.wixsite.com/wecan1/join-the-network)

---

<div class="post-metadata">

**Author:** ![Shan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/shan/32/106059_2.png) [@Shan](https://forum.wixstudio.com/u/Shan)\
**Post date:** [June 26, 2018, 1:47am UTC](https://forum.wixstudio.com/t/wix-code-sending-form-submission-to-three-recipients/33889/14 "2018-06-26T01:47:20Z")

</div>

hi,

try this for line 8

import {sendEmail, sendEmailWithRecipient, sendThirdEmail}

---

<div class="post-metadata">

**Author:** ![jessicasilvers28](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jessicasilvers28/32/3932_2.png) [@jessicasilvers28](https://forum.wixstudio.com/u/jessicasilvers28)\
**Post date:** [June 26, 2018, 4:37pm UTC](https://forum.wixstudio.com/t/wix-code-sending-form-submission-to-three-recipients/33889/15 "2018-06-26T16:37:17Z")

</div>

THANK YOU for all your help Shan! This worked for me!
