# Send two emails on form submission (sendgrid API V3)

**URL:** <https://forum.wixstudio.com/t/send-two-emails-on-form-submission-sendgrid-api-v3/27815>\
**Category:** Ask the community\
**Tags:** wix-forms, question, code\
**Created:** [January 29, 2020, 6:57pm UTC](https://forum.wixstudio.com/t/send-two-emails-on-form-submission-sendgrid-api-v3/27815 "2020-01-29T18:57:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrnevs](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mrnevs/32/5651_2.png) [@mrnevs](https://forum.wixstudio.com/u/mrnevs)\
**Post date:** [January 29, 2020, 6:57pm UTC](https://forum.wixstudio.com/t/send-two-emails-on-form-submission-sendgrid-api-v3/27815/1 "2020-01-29T18:57:59Z")

</div>

Hi,

I am using sendgrid api V3 to send an email on form submission as seen here at: [https://www.vorbly.com/Vorbly-Code/WIX-SENDGRID-API-V3—AUTO-EMAIL-MESSAGES](https://www.vorbly.com/Vorbly-Code/WIX-SENDGRID-API-V3---AUTO-EMAIL-MESSAGES)

I would like to send one email to myself and another email to the forms email contact field.

However, I want to use two seperate email bodies, so send two seperate emails on form submission.

The problem I have is that the first email sends OK, but the second doesnt because it says

sendformData already declared  
const body already declared  
cont subject already declared

How can I code it so that the two seperate emails can send?

```javascript
//send email on form submit code

```

```javascript
import {sendEmail, sendEmailWithRecipient} from 'backend/email';

```

```javascript
$w.onReady(function () {

```

```javascript
 $w("#MYDATABASE").onAfterSave(sendFormData);

```

```javascript
});

```

```javascript
// Customize Your Email to yourself - EMAIL 1 //

```

```javascript
function sendFormData() {

```

```javascript
const subject = `SUBJECT`;

```

```javascript
const body =`EMAIL BODY`;

```

```javascript
sendEmail(subject, body)

```

```javascript
.then(response => console.log(response));

```

```javascript

```

```javascript
// Customize Your Email to person completing the form EMAIL 2//

```

```javascript
function sendFormData() {

```

```javascript
const subject = `SUBJECT`;

```

```javascript
const body =`EMAIL BODY`;

```

```javascript
const recipient = $w("#EMAILFORMVALUE").value;

```

```javascript
sendEmailWithRecipient(subject, body, recipient)

```

```javascript
.then(response => console.log(response));

```

```javascript
}}

```

```javascript

```

My email.jsw is:

```javascript
import { sendWithService } from 'backend/sendGrid';
export function sendEmail(subject, body) {
const key = "HIDDEN"; // Replace with your API key //
const sender = "HIDDEN"; // Sender email //
const recipient = "HIDDEN"; // Notification to yourself //
return sendWithService(key, sender, recipient, subject, body);
}
export function sendEmailWithRecipient(subject, body, recipient) {
const key = "HIDDEN"; // Replace with your API key //
const sender = "HIDDEN"; // Sender email //
return sendWithService(key, sender, recipient, subject, body); // Customer email //
}

```

---

<div class="post-metadata">

**Author:** ![samuele](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/samuele/32/10102_2.png) [@samuele](https://forum.wixstudio.com/u/samuele)\
**Post date:** [January 30, 2020, 9:57am UTC](https://forum.wixstudio.com/t/send-two-emails-on-form-submission-sendgrid-api-v3/27815/2 "2020-01-30T09:57:18Z")

</div>

Hi.

I can see from your code that you declared the sendFormData function twice, hence the issue. To send the emails properly, please follow this tutorial: [Corvid Tutorial: Sending an Email on Form Submission](https://support.wix.com/en/article/corvid-tutorial-sending-an-email-on-form-submission)

Good luck!

---

<div class="post-metadata">

**Author:** ![mrnevs](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mrnevs/32/5651_2.png) [@mrnevs](https://forum.wixstudio.com/u/mrnevs)\
**Post date:** [January 30, 2020, 11:06am UTC](https://forum.wixstudio.com/t/send-two-emails-on-form-submission-sendgrid-api-v3/27815/3 "2020-01-30T11:06:48Z")

</div>

Hi,

Fixed, had to use

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

---

<div class="post-metadata">

**Author:** ![sylvianuneza](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/sylvianuneza/32/29738_2.png) [@sylvianuneza](https://forum.wixstudio.com/u/sylvianuneza)\
**Post date:** [August 18, 2021, 12:20am UTC](https://forum.wixstudio.com/t/send-two-emails-on-form-submission-sendgrid-api-v3/27815/4 "2021-08-18T00:20:16Z")

</div>

Hi can you share an example of the code used to make this difference, did you have to edit the back end module? or only the page code?
