Customer sign-up emails not being received by me

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:

  1. An email to me - with all the customer’s registration details that they have filled out, so I can add them to my business
  2. 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!

Okay, so you are using the Wix tutorial for ‘How to send an email on form submission’ through SendGrid.
https://support.wix.com/en/article/corvid-tutorial-sending-an-email-on-form-submission

I have myself used the SendGrid tutorial on one of my websites before I changed it to all through Wix and code itself, so I can very much vouch that the above linked tutorial worked fine for myself.

You can also see Nayeli and Michael’s youtube videos about the tutorial too, both of which runs through it all thoroughly and supplies all the relevant code for it too.
https://www.youtube.com/watch?v=bPd7o7hUfGk
https://www.youtube.com/watch?v=0SVvNKNEmWk

However, please note that when I used the tutorial I did exactly as the code was shown in the tutorial itself, I had not entered extra code like you have done with the subjectAdmin, subjectRecipient and subjectBody in your code for example.

So therefore I would first suggest that you go back to the existing tutorial and see if it all works fine as like in the tutorial, if it all works fine as per the tutorial then the issue is to do with your added code that is different from the tutorial itself.

I also made sure that I had fully setup the SendGrid server authentication too, so that email progs knew that I was using SendGrid and I didn’t get emails sent to spam for example, plus I then also didn’t get the extra ‘sent by SendGrid’ line in the emails too.
https://sendgrid.com/docs/glossary/sender-authentication/
https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/

Finally, have a look through SendGrid’s own documentation and info for more help about using their own API too.
https://sendgrid.com/docs/for-developers/sending-email/api-getting-started/
https://sendgrid.com/docs/API_Reference/api_getting_started.html