willowmecreationsV2/contact.js

29 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-08-24 23:41:17 +01:00
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.");
});
});