SendGrid Email Notification Code not working

I need urgent help as I am working on a deadline for this website. I did the sendgrid set up and no emails are coming through. I will change the API Key when this gets resolved. See my Screenshots below. I have been working on this for 4 days. I’ve tried everything

Hi,

  1. any console error?
  2. did you check the spam? :slight_smile:

Liran.

No errors and not in spam. Just not coming through.

Liran,
Any thoughts? How should I proceed is there any alternative codes I could use; maybe with a different service? I need help as soon as possible. Thanks for understanding.

Can you please share a url to your site?

I started fresh with this one so I am just using a template. I will import my other items later and change the design. https://shchamberweb.wixsite.com/redo/form-test

Liran,
Is that everything you need? Let me know how else I can help.

Hi,

So I was able to send a mail (fixed the filename mostly).
Please check your email (the one you configured in the code: sh…web), as I sent a few to it :slight_smile:

I saved the site. all you need to do now is put your own API key.

Liran.

It worked! My inbox is full. What are the code updates so that I can implement it?

Just copy from the site that you posted here, I’ve saved the changes.
please note the file names (e.g. sendGrid) - it’s case sensitive.

Liran.

Wait what? Did you go into my site? Where did you save it?

In the site you gave me.
Also, note that I removed the link from the button (the one that takes to /home).
Try adding it back, and if it breaks the email sending, use wixLocation.to() for redirection.

Liran.

I just tried to submit using my own computer and nothing happened. I saw the file name change. Can you just send the code as I should type it?

Did you remember to put your own API key?
Here’s the code:


Liran.

Liran, Just tested the redirect. It did break it. I need this for almost all the forms I am going to use this with so I need a solution. Do I just put the Url of the location and do I put it in the page part of the code? Please help. Additionally, how can I incorporate a second email to the submitter of the form. Would I be able to add this to the JSW file?: export function sendEmailWithRecipient(subject, body, recipient) {
const key = “MY KEY”;
const sender = “shchamberweb@gmail.com”;
return sendWithService(key, sender, recipient, subject, body);
}
And this to the page code?: sendEmailWithRecipient(subject, body, recipient)
.then(response => console.log(response));

Redirect after sending mail will be in page code:

import {sendEmail} from 'backend/email';
import wixLocation from 'wixLocation';

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

function sendFormData() {  
const subject = `Type Your Subject Here ${$w("#input1").value}`;
const body = `Type Here: ${$w("#input1").value}
\rLabelHere: ${$w("#input2").value}
\rLabelHere: ${$w("#input3").value}
\rLabelHere: ${$w("#input4").value}
\rReason: ${$w("#textBox1").value}`;
 sendEmail(subject, body).then(response => {     
   wixLocation.to('/home');    
  });   
}

Please read and adjust.

regarding some mails, please read here: Velo Tutorial: Sending an Email on Form Submission | Help Center | Wix.com
The part of ‘Backend code’, where the recipient is a parameter to the function.

Liran.

Ok. I’ll Try both and test how it goes. Thanks!

Hey there!
I seem to be having the same problem. It doesn’t show up in my inbox. I used the site tutorial which looks very similar to the code published in the first post. Would you be able to help?

Hi Adrian,

I need some more information.
Do you have your own API key?
Can you tell me if you see any console errors?

Did you make any changes to the sample code?
If so, which?

Liran.

I am trying to send mail from my own “contact us” form. I believe that I have used basically all of the same code, except I am not saving the information to a database. I’m just trying to send it in an email. I followed this article: Velo Tutorial: Sending an Email on Form Submission | Help Center | Wix.com. I have a SendGrid API-Key (I’ve actually tried two with an equal lack of success). This is my page code:

// libraries that we need
import wixData from 'wix-data'; // Used to query database
//import wixLocation from 'wix-location'; // Used to get current page URL
import wixUsers from 'wix-users'; // Used to get the current user
import {sendEmail, sendEmailWithRecipient, sendEmailWithRecipientAndSender} from 'backend/email';
//import {sendEmailWithRecipientAndSender} from 'backend/email';

// This page is set as members only; so we just need to find out which member this is...
// and fill out the name and from email input fields, which are the first two
// on the form.  The other fields are another input field for subject and
// a text box for the message body.
$w.onReady(function () {
	// Grab the current user's ID
	let user = wixUsers.currentUser;
	
	let userId = user.id; // Grab user ID.  could just set userId = wixUsers.currentUser.id
	
	// Get this user's name and email, and put it in the appropriate inputs
	wixData.query("OurTest")
    .eq('_id', userId)
    .find()
    .then( (results) => {
      $w('#input1').value = results.items[0].userName;
   	  $w('#input2').value = results.items[0].email;
   }
      
);});

// Check that they don't have empty subject and message and send
export function button1_click() {
	if (($w('#input3').value !== "") && ($w('#textBox1').value !== "")){
		sendMsgData; 
		$w('#input3').value = "";
		$w('#textBox1').value = "Message Sent";
	}
	else{
		$w('#input3').value = "Subject Required!";
		$w('#textBox1').value = "Message Required!";
	}
	
}

function sendMsgData() {
	let user = wixUsers.currentUser;
	
	let userId = user.id;
	wixData.query("OurTest")
    .eq('_id', userId)
    .find()
    .then( (results) => {
      const sender = results.items[0].email;
   	  const recipient = results.items[0].sendEmail;
   	  const subject = `New Mesage from ${$w("#input1").value}`;
   	  const body = `Name: ${$w("#input1").value}
    	\rEmail: ${$w("#input2").value}
    	\rSubject: ${$w("#input3").value}
    	\rMessage: ${$w("#textBox1").value}`;
    	debugger;
    	console.log(body);
    	console.log (recipient);
    	sendEmail(subject, body)
    	.then(response => console.log(response)); 
 });
    //sendEmailWithRecipientAndSender(subject, body, recipient, sender)
    //.then(response => console.log(response)); 
// });
}

Eventually, I want to be able to specify the recipient and the sender (which I am grabbing out of my database). Right now, I’ve gone back to just the basic sendEmail and hard coded my email into the sendEmail function in backend/email. I added the debugger and console calls shown in this post, but I don’t see any results in the console log. Am I not handling the onClick properly for my button? At the moment, I seen to have broken my if statement; so I probably should go look at something else for a while…:frowning:

Thanks–

Al