Hi guys,
I am hoping someone can take a look a my coding below and let me know what I am doing wrong. I am trying to test out a simple triggered email after the submit button in triggered.
I’ve followed all the tutorials and just can’t seem to get it to work. The database work and upon filling in the form, it shows on the database. However, no emails arrive in the inbox when testing as a member.
Any assistance would be a big help. Thanks.
Pasted code:
import wixUsers from ‘wix-users’;
$w.onReady( function () {
$w(“#dataset1”).onAfterSave(() => {
if (wixUsers.currentUser.loggedIn) {
const userId = wixUsers.currentUser.id;
wixUsers.emailUser("Test_Email", userId, {
variables: {
“name”: $w(“#input1”).value,
“email”: $w(“#input2”).value
}
})
.then( () => {
// do something after the email was sent successfully
})
. catch ( (err) => {
// handle error that prevented the email from being sent
});
}
});
});
Hi,
in such cases it is a good idea to add some console.log statements to then and catch handlers.
Something like
.then(console.log)
.catch(console.error)
will allow you to see what happened with operation and in case of failure may log some useful details to the console.
I hope this helps to debug the issue! Let me know.
Hi Giedrius,
Thanks for the advice. I added in the statements to the code below. I’m not sure if I put them in the right spots however.
Still no emails are coming through…
import wixUsers from ‘wix-users’;
export function dataset1_afterSave() {
$w.onReady( **function** () {
$w("#dataset1").onAfterSave(() => {
if (wixUsers.currentUser.loggedIn) {
const userId = wixUsers.currentUser.id;
wixUsers.emailUser("Test_Email", userId, {
variables: {
“name”: $w(“#input1”).value,
“email”: $w(“#input2”).value
}
})
.then(console.log() => {
// do something after the email was sent successfully
})
. catch (console.error(err) => {
// handle error that prevented the email from being sent
});
}
});
});
}
Hi,
the idea is to know what is happening. It will not fix the problem, but will give you some insight on what is happening. When in Site Preview, you will see the result of the operation in Developer Console.
It should look exactly as in my snippet so:
wixUsers.emailUser("Test_Email", userId, {
variables: {
"name": $w("#input1").value,
"email": $w("#input2").value
}
})
.then(console.log)
.catch(console.error);
If there was an error, the result will be in a red line (catch catches error and console.error reports them as errors).
I see, thanks. I updated the snippet and below is what I am seeing in the Developer console:
Loading the code for the site. To debug this code, open masterPage.js in Developer Tools.
Loading the code for the Test upload page. To debug this code, open z4r4r.js in Developer Tools.
[Ready event] triggered on wix-dataset
Any ideas?