Send different triggered emails based on user input

Hi Wix Codes Experts,

First of all I’m loving Wix more now each day, and Wix Code just exploded my love for Wix! Thank you all for every contribution you put in to bring Wix Code to life.

Back to my challenge:

I created a quiz on my Wix site (strictly using only Wix features with no third-party integration), I’ve solved the codes that enabled me to run some algorithm based on user’s quiz answers to redirect them to the respective result pages after saving their responses in my collection (as my opt-in).
//this part is working fine

Next, where it doesn’t work, is for me to send the user a specific triggered email also based on user’s quiz answers while redirecting them to the respective result pages and saving their responses in my collection.
//the triggered email part didn’t work

I tried studying Sending a Triggered Email with Code | Help Center | Wix.com among other Wix resources to send a specific triggered email based on their result (as run by my algorithm), but because I already have the algorithm running inside the onAfterSave(), after trying to add the triggered email codes inside, the quiz algorithm didn’t work and no email sent.

Question 1: Where to include the triggered email code snippet correctly amidst my algorithm to decide which page to redirect the user, all inside onAfterSave()?

Question 2: When it says ‘user has to be currently logged in’ what does it mean? My quiz submit form acts like a ‘sign up’ form, so by clicking on the submit button, is that considered logged in to be able to send triggered emails to them immediately?

Question 3: How to set up each triggered email to continue to send the next sequence of emails, say 1 day later, 3 days later, 1 week later, and so on?

Here’re my current codes under the quiz answers submit button, submitQuizH:
Note: The other inputs from quiz questions are on a slideshow that has been hidden upon clicking on another button to display the final form as in the screenshot above.

export function submitQuizH_click() {
	if ($w('#txtName').valid && $w('#txtEmail').valid ) {
		$w("#dataset1").onAfterSave( () => {
 			
			if ($w('#achieverDreamer').value === 'achiever' && $w('#providerContributor').value === 'provider1' && $w('#living').value === 'together1' && $w('#communication').value === 'goodComm' && $w('#complement').value === 'complement1' && $w('#marriageCondition').value === 'happy') {
// here, I want to send a triggered email with the unique email ID "Praiseworthy01email"
				wixLocation.to("/praiseworthy-husband/");
			}
			else {
				if ($w('#communication').value === 'poorComm') {
// here, I want to send a triggered email with the unique email ID "CanGrow01email" 
 					wixLocation.to("/can-grow-love-husband/");
				}
				else if ($w('#marriageCondition').value === 'happy') {
					if ($w('#providerContributor').value === 'contributor1') { 
// here, I want to send a triggered email with the unique email ID "Loving01email"  
						wixLocation.to("/loving-husband/");
					}
					else { 
// here, I want to send a triggered email with the unique email ID "Trustworthy01email"   
						wixLocation.to("/trustworthy-husband/");
					}
				}
				else if ($w('#marriageCondition').value === 'coping') { 
// here, I want to send a triggered email with the unique email ID "CanLead01email"  
					wixLocation.to("/can-lead-husband/");
				}
				else { 
// here, I want to send a triggered email with the unique email ID "CanSave01email"  
					wixLocation.to("/can-save-husband/");
				}
			}			
		} );
	}
	else {
		$w('#txtErrSubmit').show();
	}
}

Thank you so much for helping me on this. I have been waiting to launch my quiz :slight_smile:

1 Like

As you can see in the article Sending a Triggered Email with Code | Help Center | Wix.com you cannot specify the email to send to but the user id.
This is the id of site member currently logged in (Wix Editor: Creating Members Only Pages | Help Center | Wix.com)
After they log in you can fetch their user-id and send an email using it.
You can currently only send an email right now (no scheduling of emails yet)

Ok Dalia, so it means there’s no way I can call for a triggered email if it’s just from a input form submission? My wish is to send an automated email to the email that was just entered in my input form with a personalized greeting in that email. I can’t use subscription box to do this because, firstly I have some quiz questions that they have to answer before submitting their answers along with their name and email to get the result, secondly upon submission I want to redirect them to specific page using if algorithm. These can’t be done using subscription box right? Do you have better alternative that I can use here?

Maybe end your quiz with a subscription form and then trigger an email after they subscribe?
Unfortunately sending an email directly by email address is not yet supported.