Skip to content

Instantly share code, notes, and snippets.

@ethand91
Last active December 18, 2022 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethand91/38c7296bb4789dbf463d6b7883b9acaf to your computer and use it in GitHub Desktop.
Save ethand91/38c7296bb4789dbf463d6b7883b9acaf to your computer and use it in GitHub Desktop.
Sample demonstrating the use of EmailJS
<!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