Adding an auto-response message enhances user experience by providing immediate feedback, confirming that their submission was received. Whether you’re building a personal blog, an e-commerce site, or a corporate portal, implementing a contact form with an auto-response message without relying on third-party services can save costs and give you full control over the process.
This comprehensive guide will walk you through creating a contact form with an auto-response message using vanilla HTML, CSS, and JavaScript. We’ll cover designing the form, styling it, adding validation, and implementing an auto-response feature. You’ll also find practical examples, links to free tools for testing, and tips to optimize performance. The journey begins with a visual representation of the concept, encapsulated in the SVG below.
An auto-response message serves multiple purposes:
Unlike external plugins, a custom solution avoids subscription fees and dependency risks, making it ideal for developers seeking autonomy.
To build this feature, we’ll use:
The auto-response will be a client-side message displayed immediately after submission, simulating an email auto-reply. For actual email sending, you’d need a server-side solution (e.g., PHP or Node.js), but this guide focuses on the front-end experience.
As of May 2025, the technologies used are widely supported:
Let’s build a contact form from scratch, complete with validation and an auto-response message.
The HTML includes a form with fields for name, email, and message, plus a submission button and a response area.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contact Form with Auto-Response</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Contact Us</h1>
<form id="contactForm">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
</div>
<div class="form-group">
<label for="message">Message:</label>
<textarea id="message" name="message" required></textarea>
</div>
<button type="submit">Send Message</button>
</form>
<div id="response" class="response"></div>
</div>
<script src="script.js"></script>
</body>
</html>
The CSS ensures the form is visually appealing and the response message is noticeable.
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f4f8;
}
.container {
text-align: center;
padding: 20px;
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
width: 400px;
}
.form-group {
margin-bottom: 15px;
text-align: left;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input, textarea {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
button {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
.response {
margin-top: 15px;
padding: 10px;
display: none;
background-color: #dff0d8;
color: #3c763d;
border-radius: 4px;
}
3. JavaScript Implementation
The JavaScript handles form submission, validation, and displays the auto-response.
document.getElementById('contactForm').addEventListener('submit', function(event) {
event.preventDefault();
const name = document.getElementById('name').value.trim();
const email = document.getElementById('email').value.trim();
const message = document.getElementById('message').value.trim();
const response = document.getElementById('response');
// Basic validation
if (!name || !email || !message) {
response.textContent = 'Please fill in all fields.';
response.style.display = 'block';
response.style.backgroundColor = '#f2dede';
response.style.color = '#a94442';
return;
}
if (!/^\S+@\S+\.\S+$/.test(email)) {
response.textContent = 'Please enter a valid email address.';
response.style.display = 'block';
response.style.backgroundColor = '#f2dede';
response.style.color = '#a94442';
return;
}
// Simulate form submission and auto-response
response.textContent = `Thank you, ${name}! We have received your message. We will reply to ${email} within 24 hours.`;
response.style.display = 'block';
response.style.backgroundColor = '#dff0d8';
response.style.color = '#3c763d';
// Clear form
this.reset();
// Hide response after 5 seconds
setTimeout(() => {
response.style.display = 'none';
}, 5000);
});
Include additional fields like phone number or subject:
<div class="form-group">
<label for="phone">Phone:</label>
<input type="tel" id="phone" name="phone">
</div>
Update JavaScript to validate the phone field if needed.
Add animations for better UX:
.response {
animation: fadeIn 0.5s;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
For real email sending, use a free tool like Formspree. Add a action attribute to the form:
<form id="contactForm" action="https://formspree.io/f/your-form-id" method="POST">
Replace your-form-id with your Formspree ID.
Enhance your development with these free resources: