I made a website registering new people to my business, and I have been having 2 issues.
There is a registration form that they have to complete, and then 2 emails are sent out upon submission of the registration form:
- An email to me - with all the customer’s registration details that they have filled out, so I can add them to my business
- An email to the customer - informing them they have been registered and to await further instruction
I have used SendGrid for this process, and followed the tutorials on setting up the emails on backend.
First issue - Although it is working well most of the time - I am not receiving all my customer registration emails, BUT I can see that all the customer information has been registered on the Wix Database on my website - it just hasn’t been emailed to me when they click submit on the registration page. I have had 100 customers sign up and this has occurred to 6 of them - where I have received no registration email at all . Could anyone help me please?
Second issue - Sometimes the registration email which is sent to me populates only half the information on the website - despite my code being correct. Again, with my 100 customers, this has happened to 15. I wonder if this is a problem with my code please?
Below are my backend codes:
//email.jsw
import {sendWithService} from 'backend/sendGrid';
export function sendEmail(subject, body) {
const key = "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";
const sender = "noreply@XXXX.com";
const recipient = "me@XXX.net";
return sendWithService(key, sender, recipient, subject, body);
}
export function sendEmailWithRecipient(subject, body, recipient) {
const key = "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";
const sender = "noreply@XXXX.com";
return sendWithService(key, sender, recipient, subject, body);
}
and
//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}&text=${body}`;
const request = {
"method": "post",
"headers": headers,
"body": data
};
return fetch(url, request)
.then(response => response.json());
}
and this is the email with the instruction on the actual registration page
import {sendEmail, sendEmailWithRecipient} from 'backend/email';
$w.onReady(function () {
$w("#dataset1").onAfterSave(sendFormData);
});
function sendFormData() {
const subjectAdmin = `New Customer Registration Intake Form: ${$w("#input1").value}`;
const subjectRecipient = `Thank You for Registering with us ${$w("#input1").value}`;
const bodyAdmin = `New Customer Registration Intake Form: ${$w("#input1").value} ${$w("#input3").value}
\rHello Company Name,
\rA new customer has registered via the online registration service. For their proof of ID, they have opted for "${$w("#dropdown14").value}"
\rBelow are the details of the new customer:
\rTitle: ${$w("#radioGroup1").value}
\rFirst Name: ${$w("#input1").value}
\rSurname: ${$w("#input3").value}
\rDOB: ${$w("#input30").value}
\rGender: ${$w("#dropdown8").value}
\rHome Address: ${$w("#input8").value}
\rPostcode: ${$w("#input9").value}
\rMain Phone Number: ${$w("#input10").value}
\rEmail Address: ${$w("#input12").value}
\rDate of Signature: ${$w("#datePicker2").value}
\rThank you,
\rCompany Name`;
const bodyRecipient = `Dear ${$w("#input1").value},
\rThank you for registering with Company Name. Please allow 1-2 working day for your application to be processed.
\rIf you have opted to email your proof of ID, please email your proof to: me@XXX.net
\rThank you,
\rCompany Name`;
const recipient = $w("#input12").value;
sendEmailWithRecipient(subjectRecipient, bodyRecipient, recipient)
.then(response => console.log(response));
sendEmail(subjectAdmin, bodyAdmin)
.then(response => console.log(response));
}
I would be forever grateful if you could kindly resolve this for me, as it is causing me and my business a lot of stress!
Thank you in advance!