Inside the form

Files, security and code

Before you put someone else's code on your website, you should know what it does. Here's every file in the download, how the form protects your website, and the script that sends every message.

The form is about 1,600 lines of PHP and JavaScript written for FreeContactForm, plus the well-known PHPMailer library to send the email. There's no database, no account and no outside service. All four forms (contact, quote request, appointment request and callback request) use exactly the same engine. Only the fields and settings differ.

Contents:

The files

This is the contact form download. The other forms have the same files.

fcf.form.htm                 The form. Paste it into your page.
readme.txt                   Quick installation steps
LICENSE.txt                  The licence
CHANGELOG.md                 What changed in each version
docs/
  DELIVERABILITY.md          Getting your emails delivered, not sent to spam
  UPGRADING.md               Moving to a new version

fcf-config/                  YOUR files - kept when you upgrade
  fcf.config.php             Settings: where to send, mail server, spam limits
  fcf.rules.js               Field rules for the browser check
  css/fcf.custom.css         Your colour and layout changes
  email-templates/
    fcf.email-in.htm         The email you receive (HTML)
    fcf.email-in.txt         The email you receive (plain text)
  .htaccess                  Stops your settings being downloaded

fcf-assets/                  THE ENGINE - replaced when you upgrade
  fcf.process.php            Receives the form and runs the steps below
  fcf.selftest.php           Optional page that checks your setup
  inc/
    bootstrap.php            Loads your settings and fills in defaults
    process.php              The send script, shown in full below
    functions.php            Input cleaning, spam checks, rate limits, email
    selftest.php             The self-test checks
  classes/
    FormValidate.php         Checks each field on the server
    PHPMailer.php, SMTP.php,
    Exception.php            PHPMailer, which sends the email
  js/
    fcf.form.js              Sends the form without reloading the page
    fcf.just-validate.min.js Checks the fields in the browser
    lang/fcf.en.js           Error messages (English)
  css/fcf.default.css        The form's default look

Every folder inside fcf-config and fcf-assets has an empty index.html, so a visitor can't list its contents, and the inc and classes folders have an .htaccess that blocks them from the web completely.

Your folder and the engine folder

Everything you change lives in fcf-config: your settings, your email templates, your field rules and your styles. Everything else lives in fcf-assets, and you never need to edit it.

That split makes upgrading simple. When a new version comes out, you replace fcf-assets and keep fcf-config. Your settings carry over, and if a new version ever needs a change to your settings, the form tells you.

How a message is sent

The form checks the fields in the visitor's browser, then sends them in the background to fcf.process.php. On your server, the form throws away anything it wasn't expecting, runs the spam checks, checks every field again and applies the rate limits. Then PHPMailer sends the email through your mail server, and the visitor sees your thank-you message.

For a step-by-step explanation with a diagram, see how a contact form works.

Security and spam protection

A contact form is a way into your server from the public internet, so these protections are built in:

There's no CAPTCHA, so your visitors don't have to pick out traffic lights. For most websites these checks stop the spam that matters.

What it doesn't do

Read the send script

This is fcf-assets/inc/process.php from version 2026.1.1, the script that runs every time someone presses Send. The helper functions it calls are in functions.php, in the same download.

<?php
// ... licence header ...

if (!defined('FCF_ENTRY')) {
    http_response_code(403);
    exit;
}

use PHPMailer\PHPMailer\PHPMailer;

if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') {
    http_response_code(405);
    header('Allow: POST');
    exit;
}

header('Content-Type: text/html; charset=UTF-8');
header('X-Content-Type-Options: nosniff');
header('Cache-Control: no-store');

// ******************************
// CLEAN INPUT AND SPAM CHECKS
// ******************************
// From here on every value is a plain UTF-8 string.
$_POST = sanitisePost($_POST, $rules);
checkSpamTraps();
unset($_POST['fcf_hp'], $_POST['fcf_t']);

$missing_fields = checkFieldsExist($rules);
if ($missing_fields !== '') {
    exitFail(fcfMsg('fieldConfigError') . '<ul>' . $missing_fields . '</ul>');
}

// *******************
// VALIDATE THE FIELDS
// *******************
validateFields($rules);

// Limits per visitor and for the whole site (protects the host's hourly sending allowance).
// Only the first refusal in a window is logged, so a flood cannot fill the log.
$first_refusal = false;
if (rateLimitExceeded('ip:' . fcfRateKey(fcfClientIp()), (int) RATE_LIMIT_MAX, (int) RATE_LIMIT_WINDOW, $first_refusal)) {
    if ($first_refusal) {
        fcfLog('rate-limited', 'A visitor reached RATE_LIMIT_MAX (' . (int) RATE_LIMIT_MAX . ' per ' . (int) RATE_LIMIT_WINDOW . 's)');
    }
    exitError(fcfMsg('rateLimited', 'Too many messages sent. Please try again later.'));
}
if (rateLimitExceeded('site', (int) SITE_LIMIT_MAX, (int) SITE_LIMIT_WINDOW, $first_refusal)) {
    if ($first_refusal) {
        fcfLog('site-limit', 'SITE_LIMIT_MAX (' . (int) SITE_LIMIT_MAX . ' per ' . (int) SITE_LIMIT_WINDOW . 's) was reached. New messages are refused until the window passes. Raise it if this was real traffic.');
    }
    exitError(fcfMsg('siteBusy', 'The form is very busy at the moment. Please try again in a little while.'));
}

// ************
// CREATE EMAIL
// ************
$debug = strtoupper((string) SMTP_DEBUG) === 'YES';
$debug_log = '';

try {
    $mail = fcfCreateMailer($debug, $debug_log);

    // REPLY TO (optional)
    $email_reply_to = resolveSetting((string) EMAIL_REPLY_TO);
    $email_reply_to_name = resolveSetting((string) EMAIL_REPLY_TO_NAME);
    if ($email_reply_to !== '') {
        if (!PHPMailer::validateAddress($email_reply_to)) {
            invalidAddress('REPLY TO', (string) EMAIL_REPLY_TO);
        }
        $mail->addReplyTo($email_reply_to, $email_reply_to_name);
    }

    // TO / CC / BCC
    if (fcfAddRecipients($mail, 'addAddress', (string) EMAIL_TO, (string) EMAIL_TO_NAME, 'EMAIL_TO') === 0) {
        throw new FcfConfigError('EMAIL_TO is empty. Add the address the messages should be sent to.');
    }
    fcfAddRecipients($mail, 'addCC', (string) EMAIL_TO_CC, (string) EMAIL_TO_CC_NAME, 'EMAIL_TO_CC');
    fcfAddRecipients($mail, 'addBCC', (string) EMAIL_TO_BCC, (string) EMAIL_TO_BCC_NAME, 'EMAIL_TO_BCC');

    // SUBJECT (line breaks and repeated spaces removed)
    $subject = trim(EMAIL_SUBJECT_BEFORE . ' ' . resolveSetting((string) EMAIL_SUBJECT) . ' ' . EMAIL_SUBJECT_AFTER);
    $mail->Subject = preg_replace('/\s+/u', ' ', $subject) ?? $subject;

    // BODY
    $mail->isHTML(true);
    $mail->Body = getEmailBody($rules, 'htm');
    $mail->AltBody = getEmailBody($rules, 'txt');

    $mail->send();

    if ($debug) {
        debugExit($debug_log);
    }
    isSuccess();

} catch (FcfConfigError $e) {
    // a problem in fcf-config/fcf.config.php: shown, so that it gets fixed
    exitFail($e->getMessage());
} catch (\Throwable $e) {
    // the message could not be sent. Logged without any of the visitor's details.
    fcfLog('send-failed', get_class($e) . ': ' . $e->getMessage() . ' (' . basename($e->getFile()) . ':' . $e->getLine() . ')');
    if ($debug) {
        debugExit($debug_log . "\n" . $e->getMessage());
    }
    exitError(fcfMsg('tryLater', 'Unknown error, please try later'));
}

Ready to try it? Download a form and follow the installation guide. The forms are free to use under the licence.