A modern, lightweight, and secure 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.4+ Ready – Future-proof and modern codebase
- Responsive Bootstrap 5 UI – Clean, accessible and mobile-friendly
- AJAX Form Submission – Seamless UX, no page reload
- Google reCAPTCHA v3 – Invisible and effective spam protection
- SMTP Email via PHPMailer – Secure, authenticated delivery
- User-Agent & Honeypot Spam Filtering – No bots allowed
- Client + Server Validation – Double-layered security
- Fully Customizable – Easily adapt fields, messages, and style
✅ Regex-enhanced bot detection
✅ DNS email domain validation
✅ Honeypot field
✅ reCAPTCHA score filtering
git clone https://github.com/raspgot/Contact-Form-PHP.git
Or download as ZIP.
Use a local PHP server like XAMPP, MAMP or PHP's built-in server:
php -S localhost:8000
Get your reCAPTCHA secret key from Google reCAPTCHA Admin Panel
Edit the following constants in AjaxForm.php
:
const SMTP_HOST = 'your.smtp.com';
const SMTP_USERNAME = 'your@email.com';
const SMTP_PASSWORD = 'yourpassword';
const SECRET_KEY = 'your_recaptcha_secret_key';
ℹ️ Enable the
php_curl
extension in yourphp.ini
file:extension=curl
In AjaxForm.js
, edit the key:
const RECAPTCHA_SITE_KEY = 'YOUR_RECAPTCHA_SITE_KEY';
And add the reCAPTCHA script at the end of index.html
, before </body>
:
<script src="https://www.google.com/recaptcha/api.js?render=YOUR_RECAPTCHA_SITE_KEY"></script>
Edit them directly in the HTML:
<div class="valid-feedback">Looks good !</div>
<div class="invalid-feedback">Please provide a valid name.</div>
To add fields (e.g. subject or phone):
1. Add the field in index.html
:
<input type="text" name="subject" class="form-control" required />
2. Handle it in AjaxForm.php
:
$subject = sanitize($_POST['subject']) ?? '';
3. Include it in email_template.php
:
Found a bug ? Have a suggestion ? Pull requests and feedback are welcome !
Developed with ❤️ by Raspgot
If you find this project helpful, don't forget to ⭐ star the repo !