Website: cosworthvega.com
Page: Contact Form
I have obtained the user.ID of a group of users(officers) for my site that need to be notified when a contact form has been filled out. I did this by having each officer reset their password to “Password123”. I then logged in as each user and using wix code, logged the wixID of each user and stored in a database CVOA-Officers. They then reset their password back to what it was.
The following code uses the wixUsers.emailUser API…
import wixData from ‘wix-data’;
import wixUsers from ‘wix-users’;
import wixWindow from ‘wix-window’;
import wixPay from ‘wix-pay’;
import wixCRM from ‘wix-crm’;
//>>>>>>>>>>>>>>>>>>> Multi Email >>>>>>>>>>>
// These variables are loaded in the on ready
//Presidents email
let presidentEmail;
let presidentId;
//Webmasters Email
let webmasterEmail;
let webmasterId;
//Registras Email
let registrarEmail;
let registrarId;
//VP Merchandise Director Email
let vpMerchDirEmail;
let vpMerchDirId;
// VP Membership & Finance Director
let vpMembFinanceEmail;
let vpMembFinanceId;
//the regigional director is loaded in the sendEmail function
let RegDirEmail;
let RegDirId;
//>>>>>>>>>>>>>>>>>>> Multi Email variable ends >>>>>>>>>>>
$w.onReady( function () {
//loads Registra Email
wixData.query(“CVOA-Officials”)
.eq(“title”, “Registrar”)
.find()
.then(results => {
let firstItem = results.items[0];
registrarEmail = firstItem.eMail;
registrarId = firstItem.wixId;
});
//loads Webmaster Email
wixData.query(“CVOA-Officials”)
.eq(“title”, “Webmaster”)
.find()
.then(results => {
let firstItem = results.items[0];
webmasterEmail = firstItem.eMail;
webmasterId = firstItem.wixId;
});
//loads the VP Merch email
wixData.query(“CVOA-Officials”)
.eq(“title”, “VP Merchandise Director”)
.find()
.then(results => {
let firstItem = results.items[0];
vpMerchDirEmail = firstItem.eMail;
vpMerchDirId = firstItem.wixId;
});
//loads the VP Member & Finance email
wixData.query(“CVOA-Officials”)
.eq(“title”, “VP Membership and Finance”)
.find()
.then(results => {
let firstItem = results.items[0];
vpMembFinanceEmail = firstItem.eMail;
vpMembFinanceId = firstItem.wixId;
});
//loads the president email
wixData.query(“CVOA-Officials”)
.eq(“title”, “President”)
.find()
.then(results => {
let firstItem = results.items[0];
presidentEmail = firstItem.eMail;
presidentEmail = firstItem.wixId;
});
});
export function sendButton_click(event) {
console.log(“Sending to: “, webmasterEmail + " " + webmasterId)
wixUsers.emailUser(“RC70ht8”, webmasterId, {
variables: {
“name”: $w(”#name”).value,
“email”: $w(“#email”).value,
“member”: $w(“#member”).value,
“message”: $w(“#message”).value
}
} )
.then( () => {
console.log(“MESSAGE SENT TO: " + webmasterEmail + " " + webmasterId);
} )
. catch ( (err) => {
console.log(“ERROR OCURRED SENDING…” + " " + webmasterEmail +” " + err.message);
} );
// Send to President
console.log(“Sending to: “, presidentEmail + " " + presidentId)
wixUsers.emailUser(“RC70ht8”, presidentId , {
variables: {
“name”: $w(”#name”).value,
“email”: $w(“#email”).value,
“member”: $w(“#member”).value,
“message”: $w(“#message”).value
}
} )
.then( () => {
console.log(“MESSAGE SENT TO: " + presidentEmail + " " + presidentId );
} )
. catch ( (err) => {
console.log(“ERROR OCURRED SENDING…” + " " + presidentEmail +” " + err.message);
} );
// Send to VP Membership
console.log(“Sending to: “, vpMembFinanceEmail + " " + vpMembFinanceId)
wixUsers.emailUser(“RC70ht8”, vpMembFinanceId , {
variables: {
“name”: $w(”#name”).value,
“email”: $w(“#email”).value,
“member”: $w(“#member”).value,
“message”: $w(“#message”).value
}
} )
.then( () => {
console.log(“MESSAGE SENT TO: " + vpMembFinanceEmail + " " + vpMembFinanceId );
} )
. catch ( (err) => {
console.log(“ERROR OCURRED SENDING…” + " " + vpMembFinanceEmail +” " + err.message);
} );
}
===============END CODE ===========================
Upon clicking SUBMIT I get the following errors in Developers Tools…
The FIRST message goes but the other two do not???