Contact form for static sites

Send your static site's contact form by email from CR Servers hosting: how a form posts to the endpoint, what visitor data it handles, and common errors.

A static site (plain HTML, or a Next.js, Astro or similar site exported as files) can't send email by itself. On CR Servers shared hosting, your form can post to a small contact form endpoint, contact.php, that turns each submission into an email to an address you choose. The email is sent from a mailbox on your own domain.

This page explains how to get the endpoint, how a form talks to it, and what visitor data it handles, so you can describe it in your own privacy policy.

How to get it

CR Servers staff install and configure the endpoint for you. Open a ticket and tell us:

  • The domain the form is on.
  • The address that should receive the messages.
  • Whether the email should leave out the visitor's IP address and browser (see Visitor data).
  • Whether you want Cloudflare Turnstile (see Spam protection).

Once it's set up, the endpoint answers at https://yourdomain.com/contact.php. Later changes (a new destination address, a different thank-you page, different honeypot names) also go through a ticket.

Send a form to the endpoint

Send a POST request to /contact.php from a page on the same domain. The endpoint accepts a classic HTML form (application/x-www-form-urlencoded or multipart/form-data) and JSON (application/json).

Classic HTML form

<form method="POST" action="/contact.php">
  <input type="text" name="name" required />
  <input type="email" name="email" required />
  <textarea name="message" required></textarea>

  <!-- Honeypot: people never see or fill this field -->
  <input type="text" name="company" tabindex="-1" autocomplete="off"
         aria-hidden="true" style="position:absolute;left:-9999px" />

  <button type="submit">Send</button>
</form>

After a successful submission the endpoint redirects the browser (status 303) to /contact/?sent=1. Tell us in the ticket if your thank-you page has a different address.

JavaScript (fetch)

const response = await fetch('/contact.php', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    Accept: 'application/json'
  },
  body: JSON.stringify({
    name: 'Ada Lovelace',
    email: 'ada@example.com',
    message: 'Hello'
  })
})
const result = await response.json()

The endpoint replies with JSON only when the request has the header Accept: application/json or X-Requested-With: XMLHttpRequest. Without one of them it answers like a classic form: a redirect on success and a plain-text message on error.

A JSON reply looks like {"ok":true,"error":""} on success, or {"ok":false,"error":"…"} with an error status when something is wrong. See Common errors.

Fields

You choose the field names. Every field is emailed as a name: value line, with these rules:

Field What the endpoint does
email The visitor's address. It becomes the email's Reply-To, so you can answer with Reply. A valid address is required unless we turn that off for your site (for example for a form that only asks for a phone number).
name, or firstName and lastName Used as the name on the Reply-To.
subject Becomes the email's subject (up to 200 characters). Without it, the subject is a fixed text set for your site.
company, website, url, fax, phone_ext Honeypot fields. See Spam protection.
cf-turnstile-response The Turnstile token, when Turnstile is on. It isn't emailed.
Names that start with __ Ignored.

Limits: up to 50 fields, field names up to 100 bytes, and values up to 8000 bytes each.

The endpoint doesn't send attachments. Files uploaded with the form are ignored.

Spam protection

  • Honeypot. Add a hidden field named company, website, url, fax or phone_ext and leave it empty. Bots tend to fill every field. The names match in any letter case (Company counts too). When one of these has a value, the endpoint sends nothing and reports no error: a JSON request gets the normal success reply, and a classic form gets an empty reply (status 204), so the browser stays on the form page. Don't use those names for real fields: a visitor who fills one in sees no error and you never get the email. If your form needs a real "Company" field, name it something else (for example organization) or ask us to change the honeypot names.
  • Rate limit. Each visitor IP address can make up to 40 submission attempts and send up to 8 messages per hour, per site. Attempts that fail (for example a missing email) count toward the 40.
  • Cloudflare Turnstile (optional). Turnstile is Cloudflare's CAPTCHA alternative. You create a Turnstile widget in your own Cloudflare account (your domain's DNS doesn't have to be at Cloudflare), add the widget to your page with its site key, and tell us in the ticket. We'll agree there how to get the widget's secret key to us. Once it's on, every submission must include the widget's token in the field cf-turnstile-response; a classic form with the widget inside it adds the field for you, and a fetch request has to include it in the body.

The endpoint doesn't check Google reCAPTCHA tokens.

Visitor data the endpoint handles

Use this section when you write your privacy policy. It describes the endpoint itself, in its current release (2.2.0, November 2026). If yours was installed before that, ask us in a ticket to confirm it's up to date. Server logs are a separate subject: see What the web server logs.

Data What the endpoint does with it
The form's fields Emailed to the address you chose. The endpoint keeps no copy. From there the message lives in your mailbox, like any other email.
The visitor's email address Also set as the email's Reply-To.
The visitor's IP address By default, written at the top of the email. Used for the rate limit. Sent to Cloudflare when Turnstile is on.
The visitor's browser (User-Agent) By default, written at the top of the email. Not used for anything else.

The endpoint itself sets no cookies, starts no sessions, and has no database. If an email can't be sent, it writes the mail error to the PHP error log.

Leave the IP address and browser out of the email

By default each email starts with two lines, IP: and UA:, with the visitor's IP address and browser. They help you recognise abuse. If you'd rather not receive them, ask us in a ticket and we'll turn them off for your site. The fields the visitor filled in aren't affected.

This changes only what is emailed. The endpoint still uses the IP address for the rate limit and, with Turnstile, still sends it to Cloudflare.

Rate-limit files

To count submissions, the endpoint keeps small files in a folder named .rate-limit, next to contact.php in your site's folder. The endpoint adds a rule there that tells the web server to refuse requests for the folder.

  • There is one file per visitor IP address. Its name contains a SHA-256 hash of the address, not the address itself. A hash of an IP address isn't anonymous data: someone who has the file names can test addresses against them.
  • The file holds only times: when that address tried to submit and when a message was sent, within the last hour. It never holds form fields, the email address or the browser.
  • Times older than one hour are dropped the next time the same address submits.
  • The endpoint doesn't delete these files. A file stays, with its last hour of times, until someone removes it. You can delete the rl-….json files in that folder at any time; that only resets the counters.

If your privacy policy needs these files removed on a schedule, open a ticket before you publish a retention period.

Cloudflare Turnstile

Turnstile is off unless you ask for it. When it's on:

  • The widget on your page is loaded from Cloudflare by the visitor's browser, so Cloudflare receives that visit directly.
  • For each submission, the endpoint sends the widget's token and the visitor's IP address to Cloudflare to check it.

Cloudflare is then a third party your privacy policy should name. See Cloudflare's Turnstile privacy information.

Without Turnstile, the endpoint contacts only the mail server that sends your message.

What the web server logs

A form submission is also a request to your site, so the web server records it like any other visit, whatever the endpoint's settings are. Leaving the IP address out of the email doesn't change those logs. See View your site's error and access logs for what they show and how to open them.

Common errors

Error messages are in English. With a JSON request they come in the error field; with a classic form they are shown as plain text.

Status Message What it means
405 Method Not Allowed The address was opened in a browser or requested with GET. This is normal: the endpoint only accepts POST.
404 (the site's "not found" page) The endpoint isn't installed on this site. Open a ticket.
400 A valid email address is required No field has a valid email address. Add an email field, or ask us to make it optional.
400 Please enter a message or fill at least one field. or Submission too short. The form arrived empty or nearly empty. Check the field name attributes, or the JSON body.
400 Invalid JSON body. The request says it's JSON but the body isn't valid JSON.
400 Field name too long., Field value too long., Too many fields. or Submission too large. The form is over the limits in Fields.
400 Captcha verification missing. Turnstile is on and the request has no cf-turnstile-response field.
400 Captcha verification failed. The Turnstile token is invalid, expired or already used, or Cloudflare couldn't be reached. Reset the widget and try again.
429 Too many submissions. or Too many messages sent from this address. The rate limit was reached for that IP address. It clears within an hour.
500 Mail is not configured Setup on the server isn't complete. Open a ticket.
500 Could not send message. Please try again later. The mail server refused the message, for example after the sending mailbox's password changed. Open a ticket.
503 Server busy. Please try again later. The endpoint couldn't open its rate-limit file. Try again; open a ticket if it keeps happening.

Two problems that don't show an error:

  • The form shows no error, or says it was sent, but no email arrives. Check your spam folder, then check that the form doesn't fill a honeypot field (see Spam protection).
  • Your script gets a redirect or text instead of JSON. Add the Accept: application/json header to the request.

Open a ticket if you need help. Include the domain, the time of the test, and the exact message you got.