Wix Code Form Email Notifications

Do you happen to know how to add multiple emails for the sendEmail function in the const recipient?

export function sendEmail(subject, body) {
const key = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;
const sender = “myemail@gmail.com”;
const recipient = “1email@gmail.com”; <----HERE I WOULD LIKE TO ADD MULTIPLE EMAILS
return sendWithService(key, sender, recipient, subject, body);
}

The SendGrid API if that is what you use can receive multiple emails like

to: ['recipient1@example.org', 'recipient2@example.org'],

so first you must make it possible in the sendWithService function to send this to sendGrid instead of the value you send today. Then your sendEmail function must support multiple receivers.
Maybe you could try just to insert a string delimited with ; semicolon and see how sendGrid reacts to that but make sure you know that you will expose all receivers this way.

Ahh yes makes sense. Thank you, your information led me to the solution.

Any ideas on how to not expose all of the receivers’ emails?

Perhaps calling on a Group in Wix Contacts somehow to send as a mass email labeled as the group name with no emails shown?

Hi,
What about calling the function with one recipient each time ?
Roi

Sounds like a good idea. Just not sure if I know what you mean. This is what I have that currently shows each recipients email…

//sendgrid.js
import {fetch} from ‘wix-fetch’;

export function sendWithService(key, sender, recipient, recipient2, subject, body) {
const url = “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}&to=${recipient2}&subject=${subject}&text=${body};

const request = {
“method”: “post”,
“headers”: headers,
“body”: data
};

return fetch(url, request)
.then(response => response.json());
}

//emailsubinstructorsFL.jsw

import {sendWithService} from ‘backend/sendgrid’;

export function sendEmail(subject, body) {
const key = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;
const sender = “myemail@gmail.com”;
const recipient = “email1@gmail.com”;
const recipient2 = “email2@aol.com”;
return sendWithService(key, sender, recipient, recipient2, subject, body);
}