Skip to content

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. Best of all, it’s completely jQuery-free !

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 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 !

Live Demo

Try the form live here: https://dev.raspgot.fr/github/contact-form-php

Features

  • 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.

Installation

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

Configuration

Before using the form, configure your SMTP and Google reCAPTCHA settings.

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;

Author

logo

You can visit my Portfolio and star this repo if you like it 🤖

Dependencies

About

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. Best of all, it’s completely jQuery-free !

Topics

Resources

Stars

Watchers

Forks