Triggered emails

Hi
I’m trying to create a triggered email with a simple Name and email form but nothing happens
Here is the code I use on my page
What am I doing wrong?

import wixCRM from ‘wix-crm’;
import wixUsers from ‘wix-users’;
$w.onReady( function () {
$w(‘#button5’).onClick( function () {
wixCRM.createContact({
“firstName”: $w(‘#input2’).value,
“lastName”: “Navon”,
“emails”: [$w(‘#input1’).value],
“phones”: [“0549709128”]
})
.then((id) => {
wixCRM.emailContact(‘test’, id, {
variables: {
Name: $w(‘#input2’).value,
email: $w(‘#input1’).value
}})
. catch ((err)=>{
$w(‘#text26’).text = “error sending email:” + err;
});
})
. catch ((err)=>{
$w(‘#text26’).text = “error creating contact:” + err;
});
});
});

What happens? Do you get anything in the console?

i tried again
it worked once and stopped working
you can take a look here
https://bestsiteisrael.wixsite.com/content-test/reg

Try closing the onready function before the button.onclick function is defined.

Once you create a contact, you can’t then create again. Therefore, no email would be triggered. It works once for each contact created.

1 Like

For more information, see the docs on Triggered Emails .

Is it possible to get the trigger to work every time a user submits a form?

For instance, I want to create a form that would collect a summary of what the user put down as their answer and be able to push their answers back to them for record keeping. Is there a way that could keep sending it out to each email that is put into the submission?

@nino

Take a look at the article How to Send an Email on Form Submission . For examples that you can load into your editor:

1 Like

Using a simple Wix form with Corvid Code creates some issues. You likely won’t be able to connect it to data and may have issues connecting to a variable. You might want to build a form from scratch. It only takes about 10 minutes.