Search code examples
htmlreactjsemail

dynamic values not showing up in EmailJS emails


I'm using EmailJS for creating and sending email messages.

Right now, when I submit data from a form, a message arrives in my Gmail account as expected, but the dynamic values found in {{ }} in the EmailJS template barely show up.

Here's an example:

my template looks like this:

Hi,
You've got the message from:

{{user_email}} 

{{message_subject}}

{{message}}

And here's the code of using these dynamic values:

<input
   type="text"
   name="message_subject"
   placeholder="Your message subject..."
   {...register("messageSubject")}
/>
<input
    type="email"
    name="user_email"
    placeholder="Your email..."
    {...register("userEmail")}
/>
<textarea
    name="message"
    placeholder="Describe your problem or question..."
    className={styles.textarea}
    {...register("userMessage")}
/>

When I submitted this data, I only received the message variable, the other two are not showing up

Am I missing something, i guess I'm using name attributes correctly, and they're matching to the variable's names

UPDATE: nevermind, now message is not showing up as well =(


Solution

  • The {...register("messageSubject")} can override attributes. Try to move the name attribute to the end.

    <input
       type="text"
       placeholder="Your message subject..."
       {...register("messageSubject")}
       name="message_subject"
    />