Skip to content

Instantly share code, notes, and snippets.

@iozhukau
Created December 2, 2021 07:52
Show Gist options
  • Save iozhukau/3afc96ce6dd3c526c6e78acd70cf8fa8 to your computer and use it in GitHub Desktop.
Save iozhukau/3afc96ce6dd3c526c6e78acd70cf8fa8 to your computer and use it in GitHub Desktop.
Example of a form to send an email with form data
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form>
<label for="date">Choose a date</label>
<input id="date" type="date">
<label for="email">Email</label>
<input id="email" type="email">
</form>
<a id="link" target="_blank">
<button id="button">Send mail</button>
</a>
<script>
document.getElementById("button").addEventListener("click", (e) => {
let date = document.getElementById("date").value;
let email = document.getElementById("email").value;
let title = "Hello! This mail created automatic"
let body = "Selected date is : " + date;
let href = "mailto:" + email + "?" + "subject=" + encodeURI(title) + "&" + "body=" + encodeURI(body);
let link = document.getElementById("link");
link.setAttribute("href", href);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment