Send two emails on form submission (sendgrid API V3)

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

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?

//send email on form submit code
import {sendEmail, sendEmailWithRecipient} from 'backend/email';
$w.onReady(function () {
 $w("#MYDATABASE").onAfterSave(sendFormData);
});
// Customize Your Email to yourself - EMAIL 1 //
function sendFormData() {
const subject = `SUBJECT`;
const body =`EMAIL BODY`;
sendEmail(subject, body)
.then(response => console.log(response));

// Customize Your Email to person completing the form  EMAIL 2//
function sendFormData() {
const subject = `SUBJECT`;
const body =`EMAIL BODY`;
const recipient = $w("#EMAILFORMVALUE").value;
sendEmailWithRecipient(subject, body, recipient)
.then(response => console.log(response));
}}

My email.jsw is:

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 //
}

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

Good luck!

Hi,

Fixed, had to use

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

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?