send notification email on clicking submit button form

hello all
i would like to receive an email when someone submit a form.

regards

There is a great sample on using SendGrid with Wix Code that will help you.

thanks for your reply,
i tried this way but didnt work for me !! , my codes as below could you please see where is the issue is ?

// Filename: backend/email.jsw (web modules need to have a .jsw extension)import {sendWithService} from ‘backend/sendGrid’;
import {sendWithService} from ‘backend/sendGrid’;

export function sendEmail(subject, body) {
const key = “QL.cFH5YHZQQ2_fG0z_KuQ.6WPTYEyjN1C3_7Wt9Hb3jGfkJNAyzJhz3ddhM”;
const sender = “siyamandm@gmail.com”;
const recipient = “siamandm@gmail.com”;
return sendWithService(key, sender, recipient, subject, body);
}

export function sendEmailWithRecipient(subject, body, recipient) {
const key = “QL.cFH5YHZQQ2_fG0z_KuQ.6WPTYEyjN1C3_7Wt9Hb3jGfkJNAyzJhz3ddhM”;
const sender = “siyamandm@gmail.com”;
return sendWithService(key, sender, recipient, subject, body);
}

and the 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 my page code is as below :

// For full API documentation, including code examples, visit Velo API Reference - Wix.com

$w.onReady( function () {
//TODO: write your page related code here…

});
import {sendEmail, sendEmailWithRecipient} from ‘backend/email’;

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

function sendFormData() {
const subject = New Submission from ${$w("#SellerName").value};
const body = `Name: ${$w(“#SellerName”).value}

\rSport: ${$w("#currency").value} 
\rComments: ${$w("#info").value}`; 

// const recipient = $w(“#emailInput”).value;

sendEmailWithRecipient(subject, body, )
.then(response => console.log(response));
}

there is an important Note: you have to modify your API key , where i get this key please may be that is why its not working?

regards

Hey,
You can check out also the triggered email feature.

Best,
Tal.

Hi Siyamand Rashid.

In your posted example, it seems that the example uses the https://sendgrid.com/ service to send the email.
So the API key mentioned in the article should be retrieved from the sendgrid service.

Regards,
Genry.

i have used the API provided by sendgrid but still not working

Hi,
Do you receive an error?
Did you check the spam folder?
Roi.