diff --git a/contact.html b/contact.html index 2878e93..25172e1 100644 --- a/contact.html +++ b/contact.html @@ -41,11 +41,16 @@

Send me a message!

Have questions or special requests? Reach out to me!

+

Don't wanna use the form below? M y email is just underneath it!

+
+ + +
@@ -80,6 +85,10 @@ + + \ No newline at end of file diff --git a/contact.js b/contact.js new file mode 100644 index 0000000..d732811 --- /dev/null +++ b/contact.js @@ -0,0 +1,28 @@ +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."); + }); +}); diff --git a/script.js b/script.js index 91e93b0..e7739ac 100644 --- a/script.js +++ b/script.js @@ -51,28 +51,4 @@ document.addEventListener("DOMContentLoaded", function () { }); }); -// Contact Form Functionality with EmailJS -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 = { - name: document.getElementById("name").value, - subject: document.getElementById("subject").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!"); - }, function(error) { - console.error("Failed to send message:", error); - alert("Failed to send message. Please try again later."); - }); -});