A static website can display a contact form, but it cannot send email by itself. The form needs a destination that accepts the submission: a dedicated form service, a serverless endpoint, or an API you control. Never put email-provider API keys in browser JavaScript.
Option 1: use a form endpoint
Create a form endpoint with a provider you trust, then use the URL it gives you as the form action. This example shows the structure; replace the action URL with your own endpoint.
<form action="https://form-provider.example/your-form-id" method="post">
<label>Name <input name="name" required></label>
<label>Email <input name="email" type="email" required></label>
<label>Message <textarea name="message" required></textarea></label>
<button type="submit">Send message</button>
</form>
Configure the provider’s recipient address, spam controls, and success redirect in its dashboard. Send a test message after deployment and confirm both the success page and received email.
Option 2: call your own API
If you own an API, submit JSON to it with JavaScript. The API must allow your site’s origin with CORS and must validate input server-side. Rate-limit it, add spam protection, and send mail only from the server.
Make the form usable
- Use real
labelelements, not placeholder text alone. - Mark required fields with
requiredand usetype="email". - Show a clear success or error message.
- Add a privacy note explaining where messages are sent.
- Use CAPTCHA or a honeypot when spam becomes a problem.
Do not use a mailto: link as a form backend. It depends on the visitor having a mail application configured and creates a poor mobile experience.