I have done similar for a Choir website, have a look at code here.
import wixCRM from 'wix-crm';
$w.onReady(function () {
$w("#JoinUsForm").onAfterSave(() => {
let startDate = $w("#startDate").value;
let firstName = $w('#firstName').value;
let lastName = $w('#lastName').value;
let email = $w("#email").value;
let choirRole = $w("#choirRole").value;
let readMusic = $w("#readMusic").value;
let choirBefore = $w("#choirBefore").value;
let startNow = $w("#startNow").value;
wixCRM.createContact({
"firstName": firstName,
"lastName": lastName,
"emails": [email],
"Choir Role": choirRole,
"Read Music": readMusic,
"Choir Before": choirBefore,
"Start Now": startNow,
"Start Date": startDate
})
.then((contactId) => {
// Need to use the triggered email name
return wixCRM.emailContact('joiningusform', contactId, {
"variables": {
// Need to use the triggered email variable names
"firstName": firstName,
//"lastName": $w('#lastName').value, << - not defined in the triggered email
//"emails": [$w("#email").value], << - cannot have array here
"email": email, // << - correct variable is email not emails
"choirRole": choirRole,
"readMusic": readMusic,
"choirBefore": choirBefore,
"startNow": startNow,
"startDate": startDate.toLocaleDateString('en-GB', { weekday: 'short', day: 'numeric', month: 'short', year: 'numeric'})
}
});
})
.catch((err) => {
// handle the error if the email wasn't sent
console.log(`Error: ${err}`);
});
});
});