Last active
December 18, 2022 10:01
-
-
Save ethand91/38c7296bb4789dbf463d6b7883b9acaf to your computer and use it in GitHub Desktop.
Sample demonstrating the use of EmailJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>EmailJS Example</title> | |
</head> | |
<body> | |
<form id="contact-form" onSubmit="handleForm()"> | |
<label for="fullname">Fullname</label> | |
<input type="text" name="from_name" /> | |
<br/><br/> | |
<label for="email">Your Email</label> | |
<input type="email" name="from_email"/> | |
<br/><br/> | |
<label for="subject">Message</label> | |
<textarea name="message"></textarea> | |
<br/><br/> | |
<input type="submit" value="Send"/> | |
</form> | |
<script src="https://cdn.jsdelivr.net/npm/@emailjs/browser@3/dist/email.min.js"></script> | |
<script> | |
(function () { | |
emailjs.init('1PVVpqMraXzVXJuXv'); | |
console.log('inited'); | |
})(); | |
</script> | |
<script> | |
const handleForm = async (e) => { | |
try { | |
await emailjs.sendForm('service_qz6xzxh3x', 'template_s6llx9hxxl', document.getElementById('contact-form')); | |
alert('email sent!'); | |
} catch (error) { | |
console.error(error); | |
alert('Failed to send email'); | |
} | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment