Use Sendgrid for emailnotification

Hi There!

I followed one of the tutorials on youtube ( https://www.youtube.com/watch?v=0SVvNKNEmWk&t=663s ) how to send an email notification after form submission by using Sendgrid. I managed to get it working by setting up the backendcodes (.jws and .js) and page code. However, I have another form on my website. Exactly the same setup of the form but saving in another database ( I changed this connection with the database and other specific form codes in the page code). My thought was I can use the same backendcodes for this second form, by referring to the same importfunction in my page code:
import {sendEmail, sendEmailWithRecipient} from ‘backend/email’ ;

I double checked everything many times but receive no email when I am testing the second form. Do you know if this is possible to use two submission forms on the same backend functions? Or do you have other ideas why it’s not working?

Thank you!

Kind regards,

Vincent

You can read the actual tutorial here.
https://support.wix.com/en/article/corvid-tutorial-sending-an-email-on-form-submission

Also, this has been updated with the use of SendGrid API and SendGrid npm.
https://www.wix.com/corvid/forum/community-discussion/example-send-email-with-the-sendgrid-rest-interface
https://www.wix.com/corvid/forum/tips-tutorials-examples/example-send-email-with-the-sendgrid-npm-interface

In theory, the sendGrid.js and the email.jsw files in the backend are fine to be left as they are.

The only thing that actually changes is the page code with the dataset id name for the onAfterSave function and the form values.

Finally, note that SendGrid won’t send to certain emails and this has been added to the tutorial itself.

Important:
Using SendGrid to send emails from certain email providers may not work as expected. For example, see this notification about sending from Gmail addresses.

Depending on what you are actually doing with the email here, you might find it easier to work with a simple automation from Wix Automations.
https://support.wix.com/en/ascend-by-wix/wix-automations

Or look at using triggered emails instead.
https://support.wix.com/en/ascend-by-wix/triggered-emails

Thank you for your suggestions @GOS. For my specific situation the other options without Sendgrid are not suitable. I watched all your suggestions and it’s exactly the same as the codes I added (Also the same setup as my first form codes). Still it’s not working. My page code is as below:
import {sendEmail} from ‘backend/email’ ;

$w.onReady( function () {
$w( “#dataset4” ).onAfterSave(sendFormData);
});

function sendFormData() {
const subject = New Submission **from** ${$w( "#input11" ).value};
const body = Name: ${$w( "#input8" ).value} \rEmail: ${$w( "#input9" ).value} \rSport: ${$w( "#input10" ).value} \rComments: ${$w( "#input12" ).value};

sendEmail(subject, body)
.then(response => console.log(response));
}
The backend codes are like mentioned in the tutorial. Do you know an other way how to solve this issue?

Kind regards.

Vincent