Triggered emails sent to only one specific email

Hi,

I am experiencing very strange behavior with triggered emails. I am able to receive triggered emails only to one of my outlook accounts. It wouldn’t work to another outlook account too. It also didn’t work to hotmail, yahoo or gmail or anything.
Can anyone help me figure out the issue please.

How are you using you triggered emails?

If you are using them like this:
https://support.wix.com/en/article/corvid-tutorial-sending-a-triggered-email-to-contacts
https://support.wix.com/en/article/corvid-tutorial-sending-a-triggered-email-to-members
Then have a read of this page here:
https://support.wix.com/en/article/adding-sender-details-in-triggered-emails

If you are using a third party like this:
https://support.wix.com/en/article/corvid-tutorial-sending-an-email-on-form-submission
Then you should really make sure you set up your sender authentication:
https://sendgrid.com/docs/glossary/sender-authentication/

Plus, triggered emails will not be sent to the email of the site owner I have noticed a lot of times in my work. Could that be the case?

Finally, you could use the backend version of email user as long as you are a site member too:
https://www.wix.com/corvid/reference/wix-users-backend.html#emailUser

You can see an example of backend and frontend code on the api link above if you scroll down to the Register a user sending an email for confirmation section.

https://support.wix.com/en/article/corvid-calling-server-side-code-from-the-front-end-with-web-modules
https://www.wixshow.com/blog/creating-backend-modules-in-wix-code-and-use-promise-or-async-await-to-call-it

Hi @ givemeawhisky ,

I apologize for the delayed response. I didn’t get notification of your reply.

I am using the method explained in “sending triggered email to contacts”
I am not sending to the owner email of the website.

The strange this is this code was working few months ago and it stopped sending emails. I don’t recall if I made any changes to the code.

This is the website, I was referring to. https://www.utr.org.uk/home
If I use gandesk@mail.uc.edu, it was able to send triggered email. None of the other emails I tried didn’t work. gandesk@mail.uc.edu is not the owner email of the website.

Any help is truly appreciating. I really want this to be working asap.
In google chrome, I pressed ctrl + shift + J after loading https://www.utr.org.uk/home
after completing the questionnaire, I see “contactId does not match current session contact (401)” error mesage for any email while gandesk@mail.uc.edu says " triggered emails is sent".
Please let me know if you need any other details.

Here is the part of the code I created for sending the emails.


export function slide5a_click(event) {
console.log(customerObject);
console.log(customerobject2_final);
$w(‘#dataset1’).setFieldValues(customerObject);
$w(‘#dataset1’).setFieldValues(customerobject2_final);
$w(‘#dataset1’).save();
$w(‘#button34’).hide();
$w(‘#text22’).hide();
$w(‘#input1’).hide();
$w(‘#input2’).hide();
$w(‘#input3’).hide();
$w(‘#button17’).hide();
$w(‘#button35’).show();

wixCRM.createContact({ 

“firstName”: $w(“#input1”).value,
“emails”: [$w(“#input2”).value],
//“phones”: [$w(“#input3”).value],
“customField_DoUhaveUTR”: customerObject.DoUhaveUTR,
“customField_UTRpurpose”: customerObject.UTRpurpose,
“customField_DidUearn”: customerObject.DidUearn,
“customField_SubmittedUKtax”: customerObject.SubmittedUKtax,
“customField_self_Employed”: customerObject2.self_Employed,
“customField_cisWorker”: customerObject2.cisWorker,
“customField_businessPartner”: customerObject2.businessPartner,
“customField_company_Director”: customerObject2.company_Director,
“customField_propertyLandlord”: customerObject2.propertyLandlord,
“customField_investIncome10k”: customerObject2.investIncome10k,
“customField_earnOver100k”: customerObject2.earnOver100k
})
.then((contactId) => {
wixCRM.emailContact(“RJaNdVi”, contactId, {
“variables”: {
“name”: $w(“#input1”).value,
“DoUhaveUTR_”: DoUhaveUTR_,
“UTRpurpose_”: UTRpurpose_,
“DidUearn_”: DidUearn_,
“YouAreField_”: YouAreField_,
“SubmittedUKtax_”: SubmittedUKtax_
}
})
.then(() => {
console.log(“Triggered email sent”);
})
. catch ((err) => {
console.log(err);

            }); 
    }); 

}


Here is the complete code that is in the page.


import wixCRM from ‘wix-crm’;
import { sendToMailChimp } from ‘backend/mailChimp.jsw’;

//$w.onReady(() => {
//waitForLoading();
//});
//function waitForLoading() {
// setTimeout(() => {
// $w(‘#preloader’).hide(‘FadeOut’);
// }, 1500);
//}
// For full API documentation, including code examples, visit Velo API Reference - Wix.com

var name = “”;
var DoUhaveUTR_ = “”;
var UTRpurpose_ = “”;
var DidUearn_ = “”;
var YouAreField_ = “”;
var SubmittedUKtax_ = “”;
//$w.onReady(function () {
// console.log(“alele”);
// //TODO: write your page related code here…
//});

let customerObject = { DoUhaveUTR: “”, UTRpurpose: “NA”, DidUearn: “”, SubmittedUKtax: “” }
let customerObject2 = { self_Employed: “NA”, cisWorker: “NA”, businessPartner: “NA”, company_Director: “NA”, propertyLandlord: “NA”, investIncome10k: “NA”, earnOver100k: “NA” }
let customerobject2_final = { YouAreField: “NA” }

export function slide0a_click(event) {
customerObject.DoUhaveUTR = “Yes”;
DoUhaveUTR_ = “Thanks for contacting us to obtain a UTR number!”;
$w(‘#slideshow1’).changeSlide(2);

$w('#columnStrip8').hide("fade"); 
$w('#columnStrip9').hide("fade"); 
$w('#columnStrip10').hide("fade"); 
$w('#columnStrip11').hide("fade"); 
$w('#columnStrip12').hide("fade"); 
$w('#columnStrip13').hide("fade"); 
$w('#columnStrip14').hide("fade"); 
$w('#columnStrip1').hide("fade"); 
$w('#columnStrip7').hide("fade"); 
$w('#text17').hide("fade"); 
$w('#anchorMenu1').collapse(); 
$w('#button8').hide("fade"); 
$w('#horizontalMenu1').hide("fade"); 

}

export function slide0b_click(event) {
customerObject.DoUhaveUTR = “Already Have One”;
//DoUneedUTR = “You mentioned that”;
$w(‘#slideshow1’).changeSlide(1);
$w(‘#textBox1’).hide();
$w(‘#button22’).show();
$w(‘#button23’).hide();
$w(‘#button9’).show();
$w(‘#button10’).show();

$w('#columnStrip8').hide("fade"); 
$w('#columnStrip9').hide("fade"); 
$w('#columnStrip10').hide("fade"); 
$w('#columnStrip11').hide("fade"); 
$w('#columnStrip12').hide("fade"); 
$w('#columnStrip13').hide("fade"); 
$w('#columnStrip14').hide("fade"); 
$w('#columnStrip1').hide("fade"); 
$w('#columnStrip7').hide("fade"); 
$w('#text17').hide("fade"); 
$w('#anchorMenu1').collapse(); 
$w('#button8').hide("fade"); 
$w('#horizontalMenu1').hide("fade"); 

}

export function button1_click(event) {
$w(‘#slideshow1’).changeSlide(0);
}

export function slide1a_click(event) {
customerObject.UTRpurpose = “Lost”;
UTRpurpose_ = “Find the instructions to retrive your Lost UTR Number:”;
$w(‘#slideshow1’).changeSlide(2);
}

export function slide1b_click(event) {
customerObject.UTRpurpose = “Replacement”;
UTRpurpose_ = “Find the instructions to Replace your UTR Number:”;
$w(‘#slideshow1’).changeSlide(2);
}

export function slide1c_click(event) {
customerObject.UTRpurpose = “Other”;
UTRpurpose_ = “You already have a UTR!”;
$w(‘#textBox1’).show();
$w(‘#button22’).hide();
$w(‘#button23’).show();
$w(‘#button9’).hide();
$w(‘#button10’).hide();
}

export function slide1d_click(event) {
$w(‘#slideshow1’).changeSlide(2);
}

export function button2_click(event) {
$w(‘#slideshow1’).changeSlide(0);
}

export function slide2a_click(event) {
customerObject.DidUearn = “Yes”;
$w(‘#slideshow1’).changeSlide(3);
DidUearn_ = “Instructions for a person earning more than 1000 Pounds:”
}

export function slide2b_click(event) {
customerObject.DidUearn = “No”;
$w(‘#slideshow1’).changeSlide(3);
DidUearn_ = “Instructions for a person earning less than 1000 Pounds:”
}

export function button3_click(event) {
$w(‘#slideshow1’).changeSlide(2);
}

var slide3a = 1;
export function slide3a_click(event) {
$w(‘#button28’).show();
if (slide3a === 0) {
$w(‘#button13’).style.backgroundColor = “#F16876”;
customerObject2.self_Employed = “NA”;
slide3a = 1;
} else {
$w(‘#button13’).style.backgroundColor = “#273B7B”;
customerObject2.self_Employed = “self_Employed”;
slide3a = 0;
}
}

var slide3b = 1;
export function slide3b_click(event) {
$w(‘#button28’).show();
if (slide3b === 0) {
$w(‘#button14’).style.backgroundColor = “#F16876”;
customerObject2.cisWorker = “NA”;
slide3b = 1;
} else {
$w(‘#button14’).style.backgroundColor = “#273B7B”;
customerObject2.cisWorker = “cisWorker”;
slide3b = 0;
}
}

var slide3c = 1;
export function slide3c_click(event) {
$w(‘#button28’).show();
if (slide3c === 0) {
$w(‘#button20’).style.backgroundColor = “#F16876”;
customerObject2.businessPartner = “NA”;
slide3c = 1;
} else {
$w(‘#button20’).style.backgroundColor = “#273B7B”;
customerObject2.businessPartner = “businessPartner”;
slide3c = 0;
}
}

var slide3d = 1;
export function slide3d_click(event) {
$w(‘#button28’).show();
if (slide3d === 0) {
$w(‘#button21’).style.backgroundColor = “#F16876”;
customerObject2.company_Director = “NA”;
slide3d = 1;
} else {
$w(‘#button21’).style.backgroundColor = “#273B7B”;
customerObject2.company_Director = “company_Director”;
slide3d = 0;
}
}

var slide3e = 1;
export function slide3e_click(event) {
$w(‘#button28’).show();
if (slide3e === 0) {
$w(‘#button24’).style.backgroundColor = “#F16876”;
customerObject2.propertyLandlord = “NA”;
slide3e = 1;
} else {
$w(‘#button24’).style.backgroundColor = “#273B7B”;
customerObject2.propertyLandlord = “propertyLandlord”;
slide3e = 0;
}
}

var slide3f = 1;
export function slide3f_click(event) {
$w(‘#button28’).show();
if (slide3f === 0) {
$w(‘#button25’).style.backgroundColor = “#F16876”;
customerObject2.investIncome10k = “NA”;
slide3f = 1;
} else {
$w(‘#button25’).style.backgroundColor = “#273B7B”;
customerObject2.investIncome10k = “investIncome10k”;
slide3f = 0;
}
}

var slide3g = 1;
export function slide3g_click(event) {
$w(‘#button28’).show();
if (slide3g === 0) {
$w(‘#button26’).style.backgroundColor = “#F16876”;
customerObject2.earnOver100k = “NA”;
slide3g = 1;
} else {
$w(‘#button26’).style.backgroundColor = “#273B7B”;
customerObject2.earnOver100k = “earnOver100k”;
slide3g = 0;
}
}

var slide3h = 1;
export function slide3h_click(event) {
$w(‘#button28’).show();
if (slide3h === 0) {
$w(‘#button27’).style.backgroundColor = “#F16876”;
slide3h = 1;
$w(‘#textBox2’).hide();
} else {
$w(‘#button27’).style.backgroundColor = “#273B7B”;
slide3h = 0;
$w(‘#textBox2’).show();
}
}

var slide3i = 1;
export function slide3i_click(event) {
$w(‘#slideshow1’).changeSlide(4);
customerobject2_final.YouAreField = customerObject2.self_Employed + “
” + customerObject2.company_Director + “
” + customerObject2.propertyLandlord + “
” + customerObject2.investIncome10k + “
” + customerObject2.earnOver100k + “
” + customerObject2.businessPartner + “
” + customerObject2.cisWorker;
}

export function button4_click(event) {
$w(‘#slideshow1’).changeSlide(3);
}

export function slide4a_click(event) {
customerObject.SubmittedUKtax = “Yes”;
$w(‘#slideshow1’).changeSlide(5);
SubmittedUKtax_ = “Instructions for a person who submitted UK tax:”
}

export function slide4b_click(event) {
customerObject.SubmittedUKtax = “No”;
$w(‘#slideshow1’).changeSlide(5);
SubmittedUKtax_ = “Instructions for a person who didn’t submit UK tax:”
}

export function button5_click(event) {
$w(‘#slideshow1’).changeSlide(4);
}

export function slide5a_click(event) {
console.log(customerObject);
console.log(customerobject2_final);
$w(‘#dataset1’).setFieldValues(customerObject);
$w(‘#dataset1’).setFieldValues(customerobject2_final);
$w(‘#dataset1’).save();
$w(‘#button34’).hide();
$w(‘#text22’).hide();
$w(‘#input1’).hide();
$w(‘#input2’).hide();
$w(‘#input3’).hide();
$w(‘#button17’).hide();
$w(‘#button35’).show();

wixCRM.createContact({ 

“firstName”: $w(“#input1”).value,
“emails”: [$w(“#input2”).value],
//“phones”: [$w(“#input3”).value],
“customField_DoUhaveUTR”: customerObject.DoUhaveUTR,
“customField_UTRpurpose”: customerObject.UTRpurpose,
“customField_DidUearn”: customerObject.DidUearn,
“customField_SubmittedUKtax”: customerObject.SubmittedUKtax,
“customField_self_Employed”: customerObject2.self_Employed,
“customField_cisWorker”: customerObject2.cisWorker,
“customField_businessPartner”: customerObject2.businessPartner,
“customField_company_Director”: customerObject2.company_Director,
“customField_propertyLandlord”: customerObject2.propertyLandlord,
“customField_investIncome10k”: customerObject2.investIncome10k,
“customField_earnOver100k”: customerObject2.earnOver100k
})
.then((contactId) => {
wixCRM.emailContact(“RJaNdVi”, contactId, {
“variables”: {
“name”: $w(“#input1”).value,
“DoUhaveUTR_”: DoUhaveUTR_,
“UTRpurpose_”: UTRpurpose_,
“DidUearn_”: DidUearn_,
“YouAreField_”: YouAreField_,
“SubmittedUKtax_”: SubmittedUKtax_
}
})
.then(() => {
console.log(“Triggered email sent”);
})
. catch ((err) => {
console.log(err);

            }); 
    }); 

}

export function dataset1_afterSave_1() {
// Only if user is subscribing

// Format data (field names must be those specified by MailChimp)
var data = {
“email_address”: $w(“#input2”).value,
“merge_fields”: {
“FNAME”: $w(“#input1”).value,
“PHONE”: $w(“#input3”).value,
“MMERGE3”: customerObject.DoUhaveUTR,
“MMERGE4”: customerObject.UTRpurpose,
“MMERGE5”: customerObject.DidUearn,
“MMERGE6”: customerObject.SubmittedUKtax,
“MMERGE7”: customerObject2.self_Employed,
“MMERGE8”: customerObject2.cisWorker,
“MMERGE9”: customerObject2.businessPartner,
“MMERGE10”: customerObject2.company_Director,
“MMERGE11”: customerObject2.propertyLandlord,
“MMERGE12”: customerObject2.investIncome10k,
“MMERGE13”: customerObject2.earnOver100k
},
“status”: “subscribed”
};

// Stringify into JSON format
data = JSON.stringify(data, ‘\t’);

// Process request
sendToMailChimp(data);

}

First question would be why have you cancelled out the onReady call at the start of your page code as you need that.
https://www.wix.com/corvid/reference/$w.html#onReady

Wix already lets you connect MailChimp to your contacts.
https://support.wix.com/en/article/connecting-your-wix-contacts-with-mailchimp

It also looks to me like you are mixing up the send triggered email to contacts code…
https://support.wix.com/en/article/corvid-tutorial-sending-a-triggered-email-to-contacts

…with the sending a email on form submission code.
https://support.wix.com/en/article/corvid-tutorial-sending-an-email-on-form-submission

Make your mind up with which form type you want to use.

If you are wanting to use MailChimp from the backend, then you are best to use the email on form submission and make sure that you have followed the tutorial with adding the appropriate replacements for MailChimp instead of SendGrid’s api keys etc.

Also, MailChimp have their own API with their own support pages, so you could even look at connecting to their api directly.
https://support.wix.com/en/article/corvid-accessing-third-party-services-with-the-fetch-api

Also, you can add your own MailChimp subscription form too.
https://www.vorbly.com/Vorbly-Code/WIX-IFRAME-MAILCHIMP-SUBSCRIPTION-FORM

I use a triggered email to contacts on my website and for it to work you have to add a on after save call to your code and set it up similar to what I have done below.

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,
"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}`);
}); 
}); 
}); 

Thanks for the reply.
I agree that I may not have implemented the best methods.

When I first started scripting my code, my intention was to just send one email as soon as the user submits the form. At this point I thought using a third party tool like send grid makes it more complicated. So I chose the triggered emails. Later my idea evolved such that I wanted to store the contacts and send emails at a later stage. So I chose mailchimp for that.
I saw mailchimp has direct integration with wix contacts. But I also wanted some custom fields to be exported, so I chose mailchimp scripted into my code.

If on ready function and on after save calls are the issue, why would it send email to one Id and not to the other?
I will try to include those things and let you know if it works though.
But it would be great if you can go through it again and you see any other errors.
Thanks

I’ve used SendGrid tutorial on my site and had it all working fine with the page code and the two backend files.

However, to make sure that I had all my emails sent and received etc and didn’t get the ‘sent by SendGrid’ text on my emails either, I made use of SendGrid’s Sender and Domain Authentication.
https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/

You can try setting up your own MailChimp account to do the same.
https://mailchimp.com/help/verify-a-domain/
https://mailchimp.com/help/about-email-authentication/
https://mailchimp.com/help/set-up-custom-domain-authentication-dkim-and-spf/

Also, have a look at MailChimp’s own pages for integrating with Wix and using it’s own api.
https://mailchimp.com/help/about-connected-sites/#Connect_Your_Website_Builder
https://mailchimp.com/help/about-connected-sites/#Connect_Your_Custom_Website
https://mailchimp.com/help/about-api-keys/

Finally, have a read of this page too.
https://support.wix.com/en/article/about-marketing-integrations

plus this previous forum post too.
https://www.wix.com/corvid/forum/community-discussion/connecting-wix-to-mailchimp