Automatic email to logged-in member

Hi everyone,
I created an automatic email as per https://support.wix.com/en/article/sending-an-email-on-form-submission . It works great. Thanks.
But I would like the person not to fill-in an email address since all my members (website is for members only) are registered into an appropriate collection with their respective email addresses. I want the person to only fill in first and last names, then filter the dataset so the ‘const recipient’ gets automatically called.
See attached below print-screen.

I cannot manage to isolate the email and get it called into the recipient variable. Please kindly assist. Thanks a lot

Hi!

‘wixUsers.currentUser.getEmail()’ is an async call. therefore you need to use is as a Promise and move the sendEmail call to the success callback.
See example here .

Liran.

Hi Liran,
I have actually updated my post in the meantime since this new version much better fits my need. Please kindly see.
Thanks a lot

Hi,

I understand the issue…
I know it’s a bit confusing but the explanation for that is that Wix Users is an API for getting users info, prompting login, etc., This API connects to Wix’s built in users system, which has no connection to your database.
This means that you are holding a database that is base on Wix Users system.
Therefore, you need to get the email from the wixUsers module (with getEmail()) or to store it when a user is registered to your site (let’s say under ‘email’ field in your database).
If you do that, than you can just use dataset ‘getCurrentItem()’ and read it.

I suggest sticking to getEmail() anyway.

Liran.

Dear Liran,

I think I understand your point. I got the code to work well for sending to the current user. Out of curiosity, I tried the following to get the recipient as the one who is actually registering to my event. But it does not work.

wixData.query(‘Directory’)
.contains(‘title’, $w(‘#lastnamebox’).value)
.contains(‘firstName’, $w(‘#firstnamebox’).value)
.find()
.then( (results) => {
let recipient = results.email;
sendEmail(subject, body, recipient);
sendEmailWithRecipient(subject, body, recipient);
});

What is wrong here?

Thanks a lot