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