I’ve created a custom form that connects to a dataset. It works well and I receive the acknowledgement email reliably and quickly. However, the customer email is never created. What am I missing?
BTW, I’ve already watched the 2 videos on YouTube (How To Send An Email Notification After Form Submission in Wix - Wix Code Tutorial and How to add Wix Code Form Email Notifications) and read this article;
https://support.wix.com/en/article/corvid-tutorial-sending-an-email-on-form-submission
Thanks in advance for your help!
import {sendWithService} from ‘backend/sendGrid’;
export function sendEmail(subject, body) {
const key = “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”;
const sender = “aai@accessability.org”;
const recipient = “sales@accessability.org”;
return sendWithService(key, sender, recipient, subject, body);
}
export function sendEmailWithRecipient(subject, body, recipient) {
const key = “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”;
const sender = “aai@accessability.org”;
return sendWithService(key, sender, recipient, subject, body);
}
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}&text=${body}
;
const request = {
“method”: “post”,
“headers”: headers,
“body”: data
};
return fetch(url, request)
.then(response => response.json());
}
//PAGE CODE
import {sendEmail, sendEmailWithRecipient} from ‘backend/email’;
$w.onReady(function () {
$w(“#dsaabsi”).onAfterSave(sendFormData);
});
function sendFormData() {
const subject = Query about AABSI from ${$w("#input1").value}
;
const body = Query Details: ${$w("#input1").value} \rFirst Name: ${$w("#input1").value} \rLast Name: ${$w("#input2").value} \rEmail: ${$w("#input3").value} \rPhone: ${$w("#input4").value} \rContract Manufacturing and Assembly: ${$w("#checkbox1").checked} \rCommunity Employment: ${$w("#checkbox5").checked} \rImagine Design: ${$w("#checkbox3").checked} \rMRF: ${$w("#checkbox4").checked} \rDocument and Data Destruction: ${$w("#checkbox6").checked} \rOther: ${$w("#checkbox2").checked} \rOther Service: ${$w("#input6").value} \rComment: ${$w("#textBox1").value}
;
const recipient = $w(“#input1”).value;
sendEmailWithRecipient(subject, body, recipient)
.then(response => console.log(response));
sendEmail(subject, body)
.then(response => console.log(response));
}