Using smtpjs to send the value of the form in pure javascript

  javascript, smtp

I am trying to use SmtpJS to capture the value of my form and send it to my email.

So far I have the following form markup:

<form>
  <input type="text" name="fullname" placeholder="Full Name" />
  
  <input type="text" name="idea" placeholder="Idea" />

  <div class="fruits">
  <input type="checkbox" id="apple" name="apple" value="apple">
  <label for="apple"> Apple</label><br>
   <input type="checkbox" id="orange" name="orange" value="orange">
  <label for="orange"> Orange</label><br>
  </div>

  <div class="gender">
  <input type="radio" id="male" name="gender" value="male">
    <label for="male">Male</label><br>
    <input type="radio" id="female" name="gender" value="female">
    <label for="female">Female</label><br>
 </div>

 <input type="submit" value="submit" onclick={() => sendEmail() }/>
    
</form>

I understand in order to use smtpjs, you first need to include it like this:

<script src="https://smtpjs.com/v3/smtp.js">
</script>

And then you need a function that will actually capture and send the email like this:

function sendEmail(){

    Email.send({
        Host : "smtp.yourisp.com",
        Username : "username",
        Password : "password",
        To : '[email protected]',
        From : "[email protected]",
        Subject : "This is the subject",
        Body : "And this is the body"
    }).then(
      message => alert(message)
    );
    
    }

How do I capture the inputs values, checked checkbox and selected radio buttons values and include them on the body of my email that will send to my email?

Source: Ask Javascript Questions

LEAVE A COMMENT