skip to Main Content

I’ve been trying to set up emailjs, but for some reason, it won’t work. When I click the send button, nothing happens. Can someone take a look at my code and see what I’m doing wrong? Thanks!

here’s my form:

 <section class="form">
            <form id="myform">
                <div class="wrapperform">
       
                    <label for="first"><input id="first" name="first" type="text" placeholder=" First Name"></label>
                    <label for="last"><input id="last" name="last" type="text" placeholder=" Last Name"></label>
                    <label for="emails"><input id="emails" name="emails" type="email" placeholder=" Email"></label>
                    <label for="phone"><input id="phone" name="phone" type="text" placeholder=" Phone Number"></label>
                    <label class="textarea" for="bigtext"><textarea name="message" id="message" style="width:100%; height:100%;" placeholder=" Message"></textarea></label>
                    <button class="submit" id="submit" type="submit">SUBMIT</button>
                </div>

            </form>
        </section>

here is my JavaScript:


function sendMail(){
    let parms = {
        name: document.getElementById("first").value,
        last: document.getElementById("last").value,
        email: document.getElementById("emails").value,
        phone: document.getElementById("phone").value,
        message: document.getElementById("message").value,

    }

    emailjs.send("service_72h41ds","template_aoove3j",parms).then(alert("Email Sent!!")); 
}

const form = document.getElementById("myform");
form.addEventListener("submit", sendMail);

Not too sure what do

2

Answers


  1. add catch, check error, after params add console.log check

    Login or Signup to reply.
  2. This issue is that your button is of type="submit" – so when you click the submit button, your event fires, but then immediately submits the form, so your email does not get a chance to send.

    Add

    event.preventDefault();
    

    in the submit handler.

    or

    Change button type to type='button' and change to a click handler on the button.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search