-2

So, I'm working right now on my personal website and I already have a (contact us) form which is built with three fields name (text), email (email) and the message (textarea).

Now, I want to send that data (of the message field) to my personal email address by using JavaScript and I have no idea about how to do that.

johirpro
  • 509
  • 4
  • 16
  • Questions seeking help ("why isn't/how to make this code working?") must include the desired behavior, a specific problem or error and the **shortest code necessary to reproduce it in the question itself**. Questions without a clear problem statement are not useful to other readers. See: How to create a [mcve]. – Asons Dec 09 '18 at 17:18
  • 1
    @Gabriel Bateca try to take a look to this question/answer [here](https://stackoverflow.com/questions/7381150/how-to-send-an-email-from-javascript) where they suggest to use something like this `window.open('mailto:test@example.com?subject=subject&body=body');` – Ray Soy Dec 09 '18 at 17:23

1 Answers1

1

Code of the HTML form:

<form>
<label for="name">Name</label>
    <input type="text" id="name" name="firstname" placeholder="Your name..">
<label for="email">Name</label>
    <input type="email" name="email">
<textarea id="message"> Lorem ipsum...</textarea>
<button onclick="sendMail(); return false">Send</button>
</form>

Javascript code:

function sendMail() {
    var link = "mailto:myemail@example.com"
             + "?cc=CCaddress@example.com"
             + "&subject=" + escape("This is my subject")
             + "&body=" + escape(document.getElementById('message').value)
    ;

    window.location.href = link;
}

See more from here:
https://stackoverflow.com/a/271172/6678086

johirpro
  • 509
  • 4
  • 16