How to send a triggered Email to a member who is not a currently login member

Triggered email is good idea to send emails, but there are too many limits. For example, sending to a member with the limit is a currently long in member. sending to a contact with the limit is a newly created contact.
My case is: a student find a course (from a collection), then send a email (it is in collection with the permit) to a teacher to request the course. How to send an email to the teacher in this case ?
Thank you in advance.

Hi Jack -

One approach could be to use a Third Party API service. Yisrael from WIX has a good tutorial on how to work with the Send Grid API.

Another approach potentially, is if you want to send a WIX Triggered email, one of the most important parts of the WIX Code side (aside from actually sending the Triggered email thru WIX Code), is to capture the Member’s ID when they register to your site or when they login the next time. The code example below can help with doing that:

import wixUsers from 'wix-users';

$w.onReady(function () {
	let user = wixUsers.currentUser;

	let userId = user.id;           // "r5cme-6fem-485j-djre-4844c49"
}); 

And then save this Member/Contact’s ID and the Member’s other contact info to another Collection that you’ve created. Since WIX Code’s wix-user API does not support (as of now) getting or searching of Contacts, it may be a good idea to save a copy of this Member/Contact info to your own custom “Members” Collection for using it how you see fit.

If you need help with setting up the Triggered email and adding the code to your site’s code, I can post a little how to on that.

Nick

Hi Nick
I have a Post Course Page for teacher , at this page i get the teacher ID (that is current user id) and teacher Email when load this page, see following codes.
import wixUsers from ‘wix-users’;
$w.onReady( function () {
let user = wixUsers.currentUser;
let isLoggedIn = user.loggedIn; // true
if (isLoggedIn=== true ){
let userId = user.id; // “r5cme-6fem-485j-djre-4844c49”
$w(‘#userIDtext’).text= userId;
user.getEmail()
.then( (email) => {
let userEmail = email; // “user@something.com
$w(‘#userEmailtext’).text = userEmail;
} );
}
});
after this teacher click submit button, teacher ID and teacher Email will insert to a collection.

I have another page call Find Teacher Page, a student at here find a course from a collection(this collection have teacher ID and Email also). then click the submit button, then one email will send to the teacher.
Here. click submit button is a trigger. I also finish a Triggered Email in Dashboard.
my problem is how to write code in onClick. I can get teacher ID and teacher Email from elements in page.
Thank you !

Hi Jack -

Got it. So what you’ll now need to do is the following:

1. Setup/configure a “Triggered Email” in the WIX Dashboard.

2. Confirm the “from” email address with a code sent by WIX you’ll receive in your email.

3. Copy the WIX Code from the “Triggered Email” section (automatically provided by WIX)

4. Paste this code into your “onClick” event (replace the placeholder " " with the Teacher’s ID)
5. Test

Let me know if this works for you.

Nick

Hi Nick
After dinner I did the test. The result is very clean.
I set a collection that have two member, one is teacher and another is student. see the following.


I set the triggered email and copy some code and put into the button5 onClick, see the following.
import wixUsers from ‘wix-users’;
$w.onReady( function () {
});
export function button5_click(event) {
wixUsers.emailUser(‘myNotification’, $w(‘#teacherIDtext’).text, {
variables: {
name: $w(‘#teacherNametext’).text,
phone: $w(‘#teacherPhonetext’).text
}});
}
then publish this page, then log in use laizhihong@yahoo.com . this is a student email.
first i select the tutor Email is laizhihong88@gmail.com as a teacher, then click Button. that is not work see the following


after that i select the tutor Email is laizhihong@yahoo.com as a teacher, at this time the student and teacher is the same person. then i click the Button. now it is work good.

The conclusion: wixUsers.emailUser() just design for current long in user.
i log in use email laizhihong@yahoo.com so only this email can be used to send a email. but this email is a student email, no a teacher email.

after that i select the tutor Email is laizhihong@yahoo.com as a teacher, at this time the student and teacher is the same person. then i click the Button. now it is work good.


The conclusion: wixUsers.emailUser() just design for current long in user.
i log in use email laizhihong@yahoo.com so only this email can be used to send a email. but this email is a student email, no a teacher email.

Great. Glad it works.

i’m having the same problem.
I wish to send a mail to another member (another member ID).
But its only work if i send an email to myself (same member ID that is logged in)

@agomessantos I believe the information in this thread is outdated.
I think that since this thread Wix did add the capability to email other users from the backend.
Have a look at https://www.wix.com/corvid/reference/wix-users-backend.html

@brett-haralson I believe there’s a considerable amount of outdated information in the forum, and google results for people searching for results returns links to the wrong information. Maybe guys should consider cleaning up old threads once in a while.

If you want to email your site members then you have the two options.

Wix Users - emailUser - can only email the existing logged in user.
https://www.wix.com/corvid/reference/wix-users.html#emailUser

Wix Users Backend - emailUser - can email a specific site member by adding the appropriate emailID and their userID.
https://www.wix.com/corvid/reference/wix-users-backend.html#emailUser

It is the same with emailing contacts too who are not site members through the Wix CRM.

Wix CRM - emailContact - can only email the contact that is created at that time like when submitting a contact form through your site for example.
https://www.wix.com/corvid/reference/wix-crm.html#emailContact

Wix CRM Backend - emailContact - can email any contact by adding the appropriate emailID and contactID.
https://www.wix.com/corvid/reference/wix-crm-backend.html#emailContact

Please note the difference between Wix CRM and Wix Users.

What’s the difference between wix-crm and wix-users?

  • The CRM API contains functionality for working with your site’s contacts.

  • The Users API contains functionality for working with users who are logged-in members.

  • Note that all members are also contacts, but contacts are not necessarily members.

@experimentnoxx
It will be outdated as it is nearly a year old forum post.

Always best to check with Wix API Reference which should be kept up to date, touch wood and fingers crossed time now :wink:
https://www.wix.com/corvid/reference/

HI

I have a similar issue.

I have a website where members can post projects that they want help with. Only Members can see the project details, which is a dynamic page showing data from the projects dataset.

I would like a Member A who is currently logged in to be able to message/email the owner/contact (Member B) of the project posted, similar to other classifieds websites like a gumtree or carsales, where you can message the owner of a post directly. Member B, who filled in a form with their email and details, and is the owner of the project, has their email address in the dataset Projects.

How do i set up a triggered email so that the logged in Member A can fill in a form which is emailed to Member B, who may or may not be logged in at the time? Ie how do i set up code so that the email address (and name ideally) of Member B can be variable, matching the dynamic page with their project?

My coding skills are below par.

Thanks!

Sandeep