Need help in Triggered email in email is going when onclick function but its not going when after timeout for after 7 , 14 and 21 days … below is my code
import { triggeredEmails, contacts } from ‘wix-crm’;
$w.onReady(function () {
$w(“#submit”).onClick(() => {
const contactInfo = {
name: {
first: $w(‘#fname’).value,
last: $w(‘#lname’).value,
},
emails: [{
email: $w(‘#email’).value
}]
};
let my_Id = ‘9faf8408-311a-42ff-8f3e-d2f815357543’;
contacts.appendOrCreateContact(contactInfo)
.then((resolvedContact) => {
if (resolvedContact) {
$w('#thankyou').show();
console.log(resolvedContact);
// for non member
triggeredEmails.emailContact('makeup_quiz', resolvedContact.contactId, {
variables: {
firstName: $w('#fname').value,
lastName: $w('#lname').value
}
})
.then(() => {
console.log("makeup_quiz email sent");
})
.catch((error) => {
console.error("Error sending makeup_quiz email:", error);
});
// for member
triggeredEmails.emailMember('makeup_quiz', my_Id, {
variables: {
firstName: $w('#fname').value,
lastName: $w('#lname').value
}
});
// for non member 7 days timeout
setTimeout(() => {
triggeredEmails.emailContact('follow_up', resolvedContact.contactId, {
variables: {
firstName: $w('#fname').value,
lastName: $w('#lname').value
}
})
.then(() => {
console.log("follow_up email sent");
})
.catch((error) => {
console.error("Error sending follow_up email:", error);
});
}, 7 *24* 60 *60* 1000); // 7 days
// for non member 14 days timeout
setTimeout(() => {
triggeredEmails.emailContact('follow_up', resolvedContact.contactId, {
variables: {
firstName: $w('#fname').value,
lastName: $w('#lname').value
}
})
.then(() => {
console.log("follow_up email sent");
})
.catch((error) => {
console.error("Error sending follow_up email:", error);
});
}, 14 *24* 60 *60* 1000); // 14 days
// for non member 21 days timeout
setTimeout(() => {
triggeredEmails.emailContact('follow_up', resolvedContact.contactId, {
variables: {
firstName: $w('#fname').value,
lastName: $w('#lname').value
}
})
.then(() => {
console.log("follow_up email sent");
})
.catch((error) => {
console.error("Error sending follow_up email:", error);
});
}, 21 *24* 60 *60* 1000); // 21 days
// for members 7 days timeout
setTimeout(() => {
triggeredEmails.emailMember('follow_up', my_Id, {
variables: {
firstName: $w('#fname').value,
lastName: $w('#lname').value
}
})
.then(() => {
console.log("follow_up email sent");
})
.catch((error) => {
console.error("Error sending follow_up email:", error);
});
}, 7 *24* 60 *60* 1000); // 7 days
// for non member 14 days timeout
setTimeout(() => {
triggeredEmails.emailMember('follow_up', my_Id, {
variables: {
firstName: $w('#fname').value,
lastName: $w('#lname').value
}
})
.then(() => {
console.log("follow_up email sent");
})
.catch((error) => {
console.error("Error sending follow_up email:", error);
});
}, 14 *24* 60 *60* 1000); // 14 days
// for non member 21 days timeout
setTimeout(() => {
triggeredEmails.emailMember('follow_up', my_Id, {
variables: {
firstName: $w('#fname').value,
lastName: $w('#lname').value
}
})
.then(() => {
console.log("follow_up email sent");
})
.catch((error) => {
console.error("Error sending follow_up email:", error);
});
}, 21 *24* 60 *60* 1000); // 21 days
}
})
.catch((error) => { // error handling
console.error("Error appending or creating contact:", error);
});
});
});
export function email_input(event) { //subnit button enabling
$w(‘#submit’).enable();
}