Skip to content

A modern, lightweight, and secure contact form built with PHP and Bootstrap 5 — powered by AJAX, PHPMailer, and Google reCAPTCHA v3, with zero jQuery dependency

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, lightweight, and secure contact form built with PHP and Bootstrap 5 — powered by AJAX, PHPMailer, and Google reCAPTCHA v3, with zero jQuery dependency

Demo

🚀 Live Demo

🔗 Try the demo


✨ Features

  • PHP 8.4+ support
  • Bootstrap 5 UI – Responsive and clean
  • AJAX-based form submission – No page reloads
  • Google reCAPTCHA v3 – Prevent spam without hassle
  • PHPMailer with SMTP Auth – Secure email delivery
  • Client-side + Server-side Validation – Double-layered validation
  • Bot Protection – Includes honeypot field to trap bots

📦 Quick Installation

  1. Clone or download the repository :
git clone https://github.com/raspgot/Contact-Form-PHP.git
  1. Run it locally with a local server like XAMPP

⚙️ Configuration

Before deploying, update your SMTP and reCAPTCHA credentials

1. SMTP & reCAPTCHA Configuration

const SMTP_HOST     = 'your.smtp.com';
const SMTP_USERNAME = 'your@email.com';
const SMTP_PASSWORD = 'yourpassword';
const SECRET_KEY    = 'your_recaptcha_secret_key';

ℹ️ Ensure php_curl is enabled in your php.ini :

extension=curl

2. Frontend reCAPTCHA Setup

Replace the site key in AjaxForm.js :

const RECAPTCHA_SITE_KEY = 'YOUR_RECAPTCHA_SITE_KEY';
  • Add the reCAPTCHA script to index.html (just before </body>) :
<script src="https://www.google.com/recaptcha/api.js?render=YOUR_RECAPTCHA_SITE_KEY"></script>

🛠️ Customization

Editing Validation Messages

You can customize the success and error messages in the HTML :

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

Adding More Fields

To add custom fields (e.g. subject, phone number) :

  1. Add them to index.html :
<input type="text" name="subject" class="form-control" required />
  1. Handle them in AjaxForm.php :
$subject = sanitize($_POST['subject']) ?? '';
  1. Include them in the email body and validation

🤝 Contributing

Got a bug, idea, or suggestion? Contributions are very welcome !


Author

Logo

Developed with ❤️ by Raspgot

If you found this project helpful, ⭐️ star the repo !


Dependencies

About

A modern, lightweight, and secure contact form built with PHP and Bootstrap 5 — powered by AJAX, PHPMailer, and Google reCAPTCHA v3, with zero jQuery dependency

Topics

Resources

Stars

Watchers

Forks