So if I get this right, you are having a user submit a form, yet you are not saving it to a dataset and yet you are using Wix Data and it’s query function to run a query on a dataset.
If you are not using user inputs to submit a form, then you shouldn’t be using the exact code as shown from the tutorial.
https://support.wix.com/en/article/corvid-tutorial-sending-a-triggered-email-to-contacts
That triggered email to contacts tutorial clearly states…
Triggered Emails allow you to create a template for emails that you can send to a newly created contact, using code. Before sending the email, your code can inject information into the template to personalize it with any data that is available in your page code. In this article, we demonstrate how to use the code snippet generated by Triggered Emails to send an email to the newly created contact on the submission of a form.
Although this article uses a form submission for demonstration purposes, you can send an email from anywhere in your code. The general idea is to paste the generated snippet into your code where you want the email to be sent. Then edit the snippet so that it uses the ID of the newly created contact and the values you want to insert for the variable placeholders.
In this article, we demonstrate how to use the code snippet generated by Triggered Emails to send an email to the newly created contact on the submission of a form.
Hence why you need the onAfterSave event handler function to run the code after the user inputs have been submitted to your dataset.
Plus, as you say that you run a Wix Data query, where is that shown in your code as there is only the code snippets from the tutorial. To see why your code is not working for you, we need to see all the code that you have used and not just part of it.
If you are still struggling and want an easy route then just use Wix Automations for a reply back to them.
https://support.wix.com/en/article/about-wix-automations