Skip to content

A secure, modern PHP contact form solution using AJAX, Google reCAPTCHA v3, Bootstrap 5, and PHPMailer. Includes spam protection with honeypot, validation, and SMTP support

Notifications You must be signed in to change notification settings

raspgot/Contact-Form-PHP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contact-Form-PHP

version code size closed issues stars

A modern, secure, and customizable contact form for any PHP project Built with Bootstrap 5, powered by AJAX, PHPMailer, and Google reCAPTCHA v3 — no jQuery, no bloat
🔐 Designed for performance, accessibility, and clean code

Demo

✨ Features

  • PHP 8+ Ready – Strictly typed and future-proof
  • Bootstrap 5 UI – Responsive and accessible
  • AJAX Submission – No page reloads
  • Google reCAPTCHA v3 – Invisible spam protection
  • SMTP Delivery with PHPMailer – Secure emails
  • Auto-reply to users – Confirm receipt
  • Disposable email detection – Block throwaway addresses
  • Honeypot spam traps – Catch bots
  • Session-based rate limiting – Prevent abuse
  • Easy customization – Tailor fields and styles

🚀 Live Demo

🔗 View the demo

📦 Quick Start

  1. Clone the repository :
git clone https://github.com/raspgot/Contact-Form-PHP.git

Or download as ZIP

  1. Run it locally :

Use a local PHP server like XAMPP, MAMP or PHP's built-in server :

php -S localhost:8000

⚙️ Configuration

1. Set credentials

Get your reCAPTCHA secret key at Google reCAPTCHA

In AjaxForm.php, edit:

const SECRET_KEY    = 'your_recaptcha_secret_key';
const SMTP_HOST     = 'smtp.yourprovider.com';
const SMTP_USERNAME = 'you@example.com';
const SMTP_PASSWORD = 'yourpassword';
const SMTP_SECURE   = 'tls';
const SMTP_PORT     = 587;

Note: Enable php_curl in php.ini:

extension=curl

2. Set reCAPTCHA site key in JS

In AjaxForm.js:

const RECAPTCHA_SITE_KEY = 'YOUR_RECAPTCHA_SITE_KEY';

And in index.html:

<script src="https://www.google.com/recaptcha/api.js?render=YOUR_RECAPTCHA_SITE_KEY"></script>

✨ Advanced Features

  • Regex-based User-Agent detection (blocks common bots)
  • DNS and disposable email validation (rejects throwaway emails)
  • reCAPTCHA score filtering (requires min. score 0.5)
  • Honeypot hidden field (traps bots)
  • Session rate limiting (max 3 submissions per hour)
  • Input sanitization to prevent header injection and XSS
  • Automatic user acknowledgment email
  • Customizable email template with dynamic data

🛠️ Customization

✏️ Change validation messages

Edit the messages in index.html:

<div class="valid-feedback">Looks good !</div>
<div class="invalid-feedback">Please provide a valid name.</div>

✉️ Customize the confirmation email

The file email_template.php contains the HTML template for the confirmation email automatically sent to the user after form submission

You can modify this file to:

  • Change the content of the email
  • Add your logo and branding
  • Adjust formatting and styles

⚡ Adjust session rate limiting

By default, the form limits users to 5 submissions per hour to prevent abuse

To change this limit:

  1. Open AjaxForm.php
  2. Look for the following lines:
const MAX_ATTEMPTS = 5;
const RATE_LIMIT_DURATION = 3600; // seconds (3600 = 1 hour)
  1. Modify MAX_ATTEMPTS and RATE_LIMIT_DURATION to suit your needs

🙌 Contributing

Feel free to open issues or submit pull requests :)

🧑‍💻 Author

Logo
Developed by Raspgotcontact@raspgot.fr

If you find this project useful, please ⭐ star the repository !

📚 Dependencies

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy