willowmecreationsV2/contact.js
2024-08-24 18:41:17 -04:00

28 lines
1.1 KiB
JavaScript

document.getElementById("contactForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent the default form submission
// Initialize EmailJS
emailjs.init("BfYQtqbAmpqUEmFDF");
console.log("EmailJS initialized.");
// Prepare the template parameters
var templateParams = {
to_name: "Tristan",
from_name: document.getElementById("name").value,
reply_to: document.getElementById("email").value,
message: document.getElementById("message").value,
};
// Send the email using EmailJS
emailjs.send("service_ksnq0rd", "template_d1jme4h", templateParams)
.then(function(response) {
console.log("Email sent successfully:", response.status, response.text);
alert("Message sent successfully!");
// Clear the form fields
document.getElementById("contactForm").reset();
}, function(error) {
console.error("Failed to send message:", error);
alert("Failed to send message. Please try again later.");
});
});