Hi all, I have a triggered email that I would like sent when a guest on the site completes the contact form. I have reviewed the tutorial located here:
From my understanding, the code creates a new contact and then sends a saved shoutout “triggered email”. However, the code is not working to create a contact or send the email. I’m sure it’s something wrong on my end but cannot get it to work! I have made sure that each field and input is correctly named to correspond with my custom contact form (#input1#input2 etc), that the field name (“firstName” “emails”) exists as a title heading in my contacts database, used the triggered email code “QsHtGhN” for the triggered shoutout I created, and have followed all instructions. Extrememly frustrated! Code I’m using is:
import wixCRM from ‘wix-crm’;
$w.onReady(function () {
});
export function button3_click_1(event, $w) {
wixCRM.createContact({
“firstName”: $w(‘#input1’).value,
“emails”: [$w(“#input2”).value],
“lastName”: $w(“#input5”).value
})
.then((contactId) => {
wixCRM.emailContact(“QsHtGhN”, contactId, {
“variables”: {
“firstName”: $w(‘#input1’).value,
“emails”: $w(“#input2”).value
}
})
.then(() => {
// do something after the email was sent
})
.catch((err) => {
// handle the error if the email wasn’t sent
});
});
}
I am having a similar problem. My code shown below fails on the call to createContact(). The uninformative error message is also shown below. Any help is appreciated!
Thanks,
Daren
export function sendEmailButton_click(event, $w) {
console.log('sendEmailButton clicked');
const emailStr = $w("#email").value;
console.log('email address entered = ' + emailStr);
// Calling createContact() performs one of the following.
// (The contact information specified in the contactInfo parameter matches
// an existing contact if it contains an email address or phone number
// from an existing contact.)
// If there is a matching existing contact, it is updated with the information
// specified using the contactInfo parameter. Any existing contact information
// that is not explicity overriden in the contactInfo parameter retains its
// existing value.
// http://www.wix.com/code/reference/wix-crm.html#createContact
//
wixCRM.createContact( {
"emails": [$w("#email").value]
} )
.then ( (contactId) => {
console.log('createContact() successful');
console.log('contactID: '+contactId);
wixCRM.emailContact("assesstrigger", contactId)
.then( () => {
console.log("Triggered email sent");
} )
.catch( (err) => {
console.log(err);
} );
} )
.catch( (err) => {
console.log('Error calling createContact(): ' + err);
} );
}