Triggered email to Administrator not logged in user? (All other posts are old style so reposting)

HI

Ive seen a few posts on this but from 2018 it seems wix has updated this but wanted some further advice please.

Is it possible to show me how to modify this code so that the triggered email is sent to the administrator not the logged in user?

Thanks

F

import wixUsers from 'wix-users';
import wixLocation from 'wix-location';

$w.onReady(function () {  
  $w("#checkInsWrite").onAfterSave( () => {
 if(wixUsers.currentUser.loggedIn) {    
 const userId = wixUsers.currentUser.id;
 
      wixUsers.emailUser('sportMail', userId, {
        variables: {
            name: $w("#name").value
          }
        } )
        .then( () => {
 // do something after the email was sent successfully
          wixLocation.to("/home");
        } )
        .catch( (err) => {
 // handle error that prevented the email from being sent
          console.log(err)
        } );
    }
  } );
} );

export function submitButton_click(event) {
 // Add your code for this event here: 
    $w("#checkInsWrite").save();
}

Can anyone help me with this?

i basically need to fill out a form as an aidministrator (Me) and then have the triggered email sent to a specific email address of a user.

I have that email address of the user as a text box in the same form i just need to amend the above code some how to email that person rather than as the code is written here to email logged in user.

Thanks in advance

F

Hey Fraser,

You should try using emailContact() or emailUser() from the wix-crm-backend and wix-users-backend APIs. Either of these will allow you to choose the user you send the email too.

Hope this helps!

Dara | Corvid Team

Thanks Dara

Is there any content somewhere that someone has done this?

basically my members fill in the form for a online checkin of their progress last week and i want that email to come to me not to the logged in user which would be them.

how do i simply get the triggered email to come to me and not the logged in user?

Thanks

F

Hey @fraser :raised_hand_with_fingers_splayed:

The easiest way is to get the admin ID from the private members collection and use emailUser() on the backend to email the admin.

import wixUsersBackend from 'wix-users-backend';
const userId = 'asldjshfkljashdfkjhlsdf';

wixUsersBackend.emailUser("emailID", userId);

Hope this helps~!
Ahmad

ok ill have to play around a bit and test it out, but in your opinion what im looking to do send a triggered email to my administrator when any member fills in the specific form can be done @ahmadnasriya ?

If your interested to help me more on this please let me know im keen to learn but find it so much easier learning when shown obviously by a pro like you ?

Cheers

F

Yes it can be done, you’ll need to create a data hook (afterInsert) and use the above method to send the email.

Yes with my pleasure :blush: Contact me using the link in my profile and I’ll help you (for FREE ).