So I created a custom form (not a wix form) using user-inputs and finalized with a submit button.
email.jsw backend file:
//email
import {sendWithService} from 'database/ServiceForms';
export function sendEmail(subject, body) {
const key = ".....";
const sender = "zaksauve@gmail.com";
const recipient = "zaksauve@gmail.com";
return sendWithService(key, sender, recipient, subject, body);
}
export function sendEmailWithRecipient(subject, body, recipient) {
const key = ".....";
const sender = "zaksauve@gmail.com";
return sendWithService(key, sender, recipient, subject, body);
}
sendGrid.js backend file
//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());
}
Page file:
import {sendEmail, sendEmailWithRecipient} from 'backend/email';
$w.onReady(function () {
$w("#dataset1").onAfterSave(sendFormData);
});
function sendFormData() {
const subject = `Quote For Services ${$w("#input1").value}`;
const body = `For: ${$w("#input1").value}
\rName: ${$w("#input1").value}
\rPhone Number: ${$w("#input2").value}
\rEmail: ${$w("#input3").value}
\rEvent Location: ${$w("#input4").value}
\rDate of Event: ${$w("#datePicker1").value}
\rComments: ${$w("#textBox1").value}
\rGames: ${$w("#checkboxGroup1").value}
\rHouses/Inflatables: ${$w("#checkboxGroup3").value}
\rInstant Arcade: ${$w("#checkbox1").value}`;
const recipient = $w("#input3").value;
sendEmailWithRecipient(subject, body, recipient)
.then(response => console.log(response));
sendEmail(subject, body)
.then(response => console.log(response));
}
WEBSITE: https://info160562.wixsite.com/gotgamerentals
The database receives the input on SUBMIT. I don't receive the email though.
Any suggestions?
THANK YOU!
I have used the same tutorial for SendGrid and I never had any troubles with, although I did also make sure that I had setup server authentication as well, so that email providers know that SendGrid are sending emails on your behalf and they are not just getting classed as spam etc.
Plus it also gets rid of the tagline that SendGrid put on emails, something along the lines of 'Sent by SendGrid'.
https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/
Also, have a look at this youtube video from Michael (Wix Training Academy) as it walks you through the tutorial step by step. https://www.youtube.com/watch?v=0SVvNKNEmWk
Or this youtube video from Nayeli (Code Queen) which also walks you through the tutorial step by step. https://www.youtube.com/watch?v=bPd7o7hUfGk