I am trying to send a triggered email based on if someone submits there email in my lightbox that pops up. I’m following this tutorial Velo Tutorial: Sending a Triggered Email to Contacts | Help Center | Wix.com Currently I’ve got it to so that when someone submits their email it adds their email to my database but it doesn’t end up do anything after that
Screenshots here:
This is on my lightbox page code:
This is what the form looks like
This is what the database looks like after someone has submitted their email. I’ve tried submitting my email multiple times but nothing (greened out are my email)
As you can see just confirming none of been sent.
Simply make sure that you double check your code all the time as you are missing the array on the email value in the create contact, plus you have missed the open curly bracket and the comma on the email contact triggered email line too whilst adding a parentheses instead.
Plus, when you cut parts of the code out, after you have finished check too that you have matching pairs of curly brackets and parentheses too, as they need to be equal numbers otherwise your code will show errors.
Curly brackets and parentheses are the { and } and the ( and ) in your code.
Existing sample code.
import wixCRM from 'wix-crm';
$w.onReady(function () {
});
export function signUpButton_click(event) {
wixCRM.createContact({
"firstName": $w('#nameInput').value,
"emails": [$w("#emailInput").value],
"interest_area": $w("#interestArea").value
})
.then((contactId) => {
wixCRM.emailContact("newsletter_signup", contactId, {
"variables": {
"name": $w('#nameInput').value,
"interest_area": $w("#interestArea").value
}
})
.then(() => {
// do something after the email was sent
})
.catch((err) => {
// handle the error if the email wasn't sent
});
});
}
Once you have checked and edited your code again, then when users use the lightbox to send their email, well it should work for you.
I tried to copy the code as much as possible. i don’t have variables so I just took out the guts of that section. Still not working though
Just a thought, where are you saving the email addresses as when you create the new contact those details are passed onto the Wix CRM to be shown in your Contacts list only.
https://www.wix.com/corvid/reference/wix-crm.html
If you are saving those emails into another dataset to keep them as a accepted lightbox voucher dataset for example, then you will need to use an on after save hook in your code first.
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#onAfterSave
I’ve already done similar on my own website, so here is a code example that you can use for testing on your own page.
Note also that my code was longer and I have just stripped out all the unnecessary parts of my code that you don’t need in yours. So you can also take out the two lines of variables and email underneath the email contact part if you are not using there yourself.
Finally, as I’ve just stripped out only the unnecessary lines of my code, I haven’t edited it for matching pairs of curly brackets and parentheses.
These are the { and } and the ( and ) in the code, these need to be equal numbers of each, hence the matching pairs.
So I can definitely say now that you will have errors shown when you put the code onto your own page as there will be unequal numbers and it needs to be sorted out.
Once that is all done, then this time it should all work for you and save the submitted email first into your other dataset and then it will create a new contact in Wix CRM which you will see on your Contacts list and then finally it will send your triggered email to them.
import wixCRM from 'wix-crm';
$w.onReady(function () {
$w("#Datatsetforemails").onAfterSave(() => {
let email = $w("#email").value;
wixCRM.createContact({
"emails": [email]
})
.then((contactId) => {
// Need to use the triggered email name
return wixCRM.emailContact('triggeredemailname', contactId, {
"variables": {
"email": email
}
});
})
.catch((err) => {
// handle the error if the email wasn't sent
console.log(`Error: ${err}`);
});
});
});
@givemeawhisky What should “”#email") be populated with
NVM
Got it to work! figured out what needed to be changed.
@lilchipmunk11
$w(“#email”).value should be whatever your email user input is on the lightbox form, which is input1 in your code.
I always change the elements id names in the properties panel so that I can associate each element with the role it is being used for and it is much easier to use in code this way too.
Anyways, glad to know that you have got it all working now. Onto the next problem now!
Hello Guys! Does this still works for you? I can’t get it to work. I always get the error: Uncaught (in promise) contactId does not match current session contact (401). The contact is saved on both databases (custom and crm) but the email isn’t triggered. Any Ideas, comments, experiences? Thanks a lot!
I’m using this code but still no luck
export function sendEmail_click(event) {
$w("#dataset1").onAfterSave(() => {
let contactInfo = {
"emails": [$w('#inputEmail').value]
};
console.log(contactInfo);
wixCrm.createContact(contactInfo)
.then((contactId) => {
console.log(contactId);
return wixCrm.emailContact('Ru2ePvr', contactId)
.then(() => {
console.log('Triggered email sent')
$w('#inputEmail').value = '';
})
.catch((error) => {
console.log(`Error: ${error}`)
$w('#inputEmail').value = '';
})
})
})
}
Please observe the community guidelines and refrain from multiple posts on the same topic or question.
This is an old post and is being closed.