https://github.com/tobisamcode/mail-me-nodemailer
💌 A simple contact form that helps people send you a message. 📩 to your email. - built with JavaScript/Nodemailer 📃
https://github.com/tobisamcode/mail-me-nodemailer
expressjs javascript node-js
Last synced: about 1 year ago
JSON representation
💌 A simple contact form that helps people send you a message. 📩 to your email. - built with JavaScript/Nodemailer 📃
- Host: GitHub
- URL: https://github.com/tobisamcode/mail-me-nodemailer
- Owner: tobisamcode
- Created: 2022-08-12T01:31:52.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-08-17T09:48:53.000Z (over 3 years ago)
- Last Synced: 2023-03-10T00:56:12.244Z (about 3 years ago)
- Topics: expressjs, javascript, node-js
- Language: JavaScript
- Homepage: https://tobi-mailer.herokuapp.com/
- Size: 25.4 KB
- Stars: 8
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Implementation using async/await:
`app.js`
```javascript
const contactForm = document.querySelector(".contact-form");
let name = document.getElementById("name");
let email = document.getElementById("email");
let subject = document.getElementById("subject");
let message = document.getElementById("message");
contactForm.addEventListener("submit", (e) => {
e.preventDefault();
async function postData() {
let formData = {
name: name.value,
email: email.value,
subject: subject.value,
message: message.value
};
const response = await fetch("/", {
method: "POST",
body: JSON.stringify(formData),
headers: {
"Content-Type": "application/json"
}
});
if (!response.ok) {
throw new Error(`Request failed with status ${reponse.status}`);
}
console.log("Email sent successfully");
name.value = "";
email.value = "";
subject.value = "";
message.value = "";
console.log(formData);
}
postData();
});
```