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
- 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
- Clone the repository :
git clone https://github.com/raspgot/Contact-Form-PHP.git
- Run it locally :
Use a local PHP server like XAMPP, MAMP or PHP's built-in server :
php -S localhost:8000
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
inphp.ini
:extension=curl
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>
- 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
Edit the messages in index.html
:
<div class="valid-feedback">Looks good !</div>
<div class="invalid-feedback">Please provide a valid name.</div>
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
By default, the form limits users to 5 submissions per hour to prevent abuse
To change this limit:
- Open
AjaxForm.php
- Look for the following lines:
const MAX_ATTEMPTS = 5;
const RATE_LIMIT_DURATION = 3600; // seconds (3600 = 1 hour)
- Modify
MAX_ATTEMPTS
andRATE_LIMIT_DURATION
to suit your needs
Feel free to open issues or submit pull requests :)
Developed by Raspgot — contact@raspgot.fr
If you find this project useful, please ⭐ star the repository !