I am having five custom forms on my website. I have set up all the backend. One of my forms is working perfectly, my client and I receive an email on form submission. But I’m not receiving any email from my other forms. The data is being stored in my database while I click submit button, but the email notification does not work ! and i am using the same code for every form, just changing the titles and names!
any ideas ? anyone ?
function sendFormData() {
const subject = `Nouvelle Formulaire RC Décennale ${$w("#input1").value}`;
const body = `Nouvelle formulaire par: ${$w("#input1").value}
\rCivilité: ${$w("#dropdown1").value}
\rSituation Familiale: ${$w("#dropdown2").value}
\rProfession: ${$w("#dropdown3").value}
\rRégime Social: ${$w("#dropdown4").value}
\rNom: ${$w("#input1").value}
\rPrénom: ${$w("#input2").value}
\rdatePicker1: ${$w("#datePicker1").value}
\rAdresse: ${$w("#addressInput1").value.formatted}
\rTéléphone: ${$w("#input3").value}
\rEmail: ${$w("#input4").value}`;
const recipient = $w("#input4").value;
sendEmailWithRecipient(subject, body, recipient)
.then(response => console.log(response));
sendEmail(subject, body)
.then(response => console.log(response));
}
});
back end email.jsw
import {sendWithService} from 'backend/sendGrid';
export function sendEmail(subject, body) {
const key = "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";
const sender = "delaramhamraz@gmail.com";
const recipient = "hamraz_delaram@yahoo.com";
return sendWithService(key, sender, recipient, subject, body);
}
export function sendEmailWithRecipient(subject, body, recipient) {
const key = "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";
const sender = "delaramhamraz@gmail.com";
return sendWithService(key, sender, recipient, subject, body);
}
backend 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";
const headers = {
"Authorization": "Bearer " + key,
"Content-Type": "application/x-www-form-urlencoded"
};
const data = `from=${sender}&to=${recipient}&subject=${subject}&html=${body}`;
const request = {
"method": "post",
"headers": headers,
"body": data
};
return fetch(url, request)
.then(response => response.json());
}