A basic, simple, and secure Bootstrap contact form with AJAX submission. It features both PHP and JavaScript input validations, SMTP mail sending, domain rejection for non-existent domains, and Google reCAPTCHA v3 integration. It's completely jQuery-free !
Try the form live here: https://dev.raspgot.fr/github/contact-form-php
- PHP 8.4 (See supported versions)
- Bootstrap 5
- Ajax submission – Seamless asynchronous form handling.
- Google reCAPTCHA v3 – Protect your form from spam.
- PHPMailer SMTP Authentication – Secure email delivery.
- Validation and inputs security – Validations performed both in PHP and JavaScript.
Clone the repository or download it directly
git clone https://github.com/raspgot/Contact-Form-PHP.git
cd Contact-Form-PHP
php -S localhost:8000 # need cacert.pem in php.ini
Alternatively, you can use Laragon / XAMMP
Before using the form, configure your SMTP and Google reCAPTCHA settings.
- SMTP Sender: Configure your SMTP settings (e.g., via Infomaniak).
- Google reCAPTCHA v3: Obtain your keys from Google reCAPTCHA.
- PHPMailer Configuration: See more options in the PHPMailer examples.
const SMTP_HOST = ''; # SMTP server address
const SMTP_USERNAME = ''; # SMTP username
const SMTP_PASSWORD = ''; # SMTP password
const SECRET_KEY = ''; # Google reCAPTCHA secret key
Update your AjaxForm.js file with your reCAPTCHA site key:
const RECAPTCHA_SITE_KEY = 'RECAPTCHA_SITE_KEY';
And include the reCAPTCHA script in index.html:
<script src="https://www.google.com/recaptcha/api.js?render=RECAPTCHA_SITE_KEY"></script>
You can also customize your error messages in the HTML:
<div class="valid-feedback">Name looks good</div>
<div class="invalid-feedback">Please provide a valid name</div>
Note: Ensure the cURL extension is enabled on your server. In your php.ini
file, make sure you have:
extension=curl;
You can visit my Portfolio and star this repo if you like it 🤖