# SendGrid Email Notification Code not working

**URL:** <https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [December 17, 2017, 4:40pm UTC](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706 "2017-12-17T16:40:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![elizabethjhay](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@elizabethjhay](https://forum.wixstudio.com/u/elizabethjhay)\
**Post date:** [December 17, 2017, 4:40pm UTC](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706/1 "2017-12-17T16:40:58Z")

</div>

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

 ![](https://us1.discourse-cdn.com/wix/original/3X/9/8/98aa4c33a43a8155395f70e2f7220be32f8b835a.png)

 ![](https://us1.discourse-cdn.com/wix/original/3X/7/a/7abfee1741fe443f745ab726f9394155c925eb73.png)

 ![](https://us1.discourse-cdn.com/wix/original/3X/8/c/8ce3cf27f4bc1985fbd508e753ce8ffb4303d779.png)

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/system/32/86885_2.png) [@system](https://forum.wixstudio.com/u/system)\
**Post date:** [December 17, 2017, 5:10pm UTC](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706/2 "2017-12-17T17:10:30Z")

</div>

Hi,

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

Liran.

---

<div class="post-metadata">

**Author:** ![elizabethjhay](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@elizabethjhay](https://forum.wixstudio.com/u/elizabethjhay)\
**Post date:** [December 17, 2017, 5:15pm UTC](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706/3 "2017-12-17T17:15:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![elizabethjhay](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@elizabethjhay](https://forum.wixstudio.com/u/elizabethjhay)\
**Post date:** [December 17, 2017, 6:42pm UTC](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706/4 "2017-12-17T18:42:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/system/32/86885_2.png) [@system](https://forum.wixstudio.com/u/system)\
**Post date:** [December 17, 2017, 7:00pm UTC](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706/5 "2017-12-17T19:00:44Z")

</div>

Can you please share a url to your site?

---

<div class="post-metadata">

**Author:** ![elizabethjhay](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@elizabethjhay](https://forum.wixstudio.com/u/elizabethjhay)\
**Post date:** [December 17, 2017, 7:05pm UTC](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706/6 "2017-12-17T19:05:02Z")

</div>

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](https://shchamberweb.wixsite.com/redo/form-test)

---

<div class="post-metadata">

**Author:** ![elizabethjhay](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@elizabethjhay](https://forum.wixstudio.com/u/elizabethjhay)\
**Post date:** [December 17, 2017, 7:34pm UTC](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706/7 "2017-12-17T19:34:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/system/32/86885_2.png) [@system](https://forum.wixstudio.com/u/system)\
**Post date:** [December 17, 2017, 7:57pm UTC](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706/8 "2017-12-17T19:57:40Z")

</div>

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 🙂

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

Liran.

---

<div class="post-metadata">

**Author:** ![elizabethjhay](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@elizabethjhay](https://forum.wixstudio.com/u/elizabethjhay)\
**Post date:** [December 17, 2017, 8:00pm UTC](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706/9 "2017-12-17T20:00:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/system/32/86885_2.png) [@system](https://forum.wixstudio.com/u/system)\
**Post date:** [December 17, 2017, 8:01pm UTC](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706/10 "2017-12-17T20:01:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![elizabethjhay](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@elizabethjhay](https://forum.wixstudio.com/u/elizabethjhay)\
**Post date:** [December 17, 2017, 8:02pm UTC](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706/11 "2017-12-17T20:02:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/system/32/86885_2.png) [@system](https://forum.wixstudio.com/u/system)\
**Post date:** [December 17, 2017, 8:09pm UTC](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706/12 "2017-12-17T20:09:32Z")

</div>

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()](https://www.wix.com/code/reference/wix-location.html#to) for redirection.

Liran.

---

<div class="post-metadata">

**Author:** ![elizabethjhay](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@elizabethjhay](https://forum.wixstudio.com/u/elizabethjhay)\
**Post date:** [December 17, 2017, 8:11pm UTC](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706/13 "2017-12-17T20:11:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/system/32/86885_2.png) [@system](https://forum.wixstudio.com/u/system)\
**Post date:** [December 17, 2017, 8:15pm UTC](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706/14 "2017-12-17T20:15:48Z")

</div>

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

 ![](https://us1.discourse-cdn.com/wix/original/3X/b/b/bbf7769e3c245500dd5b19ae481e20a57fc76977.png)

 ![](https://us1.discourse-cdn.com/wix/original/3X/d/5/d59e228024374ce975911de8d357f954bd857221.png)

 ![](https://us1.discourse-cdn.com/wix/original/3X/e/9/e98bc301bef89658b79f097c152b9b599c38a938.png)  
Liran.

---

<div class="post-metadata">

**Author:** ![elizabethjhay](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@elizabethjhay](https://forum.wixstudio.com/u/elizabethjhay)\
**Post date:** [December 17, 2017, 8:37pm UTC](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706/15 "2017-12-17T20:37:18Z")

</div>

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](mailto: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));

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/system/32/86885_2.png) [@system](https://forum.wixstudio.com/u/system)\
**Post date:** [December 17, 2017, 8:48pm UTC](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706/16 "2017-12-17T20:48:00Z")

</div>

Redirect after sending mail will be in page code:

```javascript
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](https://support.wix.com/en/article/how-to-send-an-email-on-form-submission)  
The part of ‘Backend code’, where the recipient is a parameter to the function.

Liran.

---

<div class="post-metadata">

**Author:** ![elizabethjhay](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@elizabethjhay](https://forum.wixstudio.com/u/elizabethjhay)\
**Post date:** [December 17, 2017, 8:53pm UTC](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706/17 "2017-12-17T20:53:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![adrian-sean-taylor](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/adrian-sean-taylor/32/1768_2.png) [@adrian-sean-taylor](https://forum.wixstudio.com/u/adrian-sean-taylor)\
**Post date:** [January 29, 2018, 10:06pm UTC](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706/18 "2018-01-29T22:06:24Z")

</div>

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?

> **[Ash Stowe](https://adrian7130.wixsite.com/theblackboxsa/cloudquoting/Ash)**
>
> This is a description of Ash Stowe page

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/system/32/86885_2.png) [@system](https://forum.wixstudio.com/u/system)\
**Post date:** [January 30, 2018, 10:33am UTC](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706/19 "2018-01-30T10:33:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gaspar-al](https://avatars.discourse-cdn.com/v4/letter/g/cdc98d/32.png) [@gaspar-al](https://forum.wixstudio.com/u/gaspar-al)\
**Post date:** [March 25, 2018, 1:09am UTC](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706/20 "2018-03-25T01:09:01Z")

</div>

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](https://support.wix.com/en/article/how-to-send-an-email-on-form-submission). I have a SendGrid API-Key (I’ve actually tried two with an equal lack of success). This is my page code:

```javascript
// 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…☹

Thanks–

Al

[Next page](https://forum.wixstudio.com/t/sendgrid-email-notification-code-not-working/11706.md?page=2)
