Premium

Business & Agency Website

A newline in the email field turns your contact form into a spam relay — and the visitor is still shown "Thank you".

  • PHP
  • MySQL

About this project

An agency website — services, case studies, team, testimonials and a contact form — with an admin covering an enquiries inbox, services, portfolio and site settings.

For a small agency the entire website exists to produce one thing: an enquiry. The naive contact form calls mail() with the visitor's address concatenated into a From header and prints "Thank you" unconditionally. Three failures follow, all real. It stores nothing, so when mail() returns false — which it does constantly on shared hosting — the lead is gone and the visitor was told it worked. Putting unvalidated input into a mail header is email header injection: a newline lets an attacker append Bcc and turn the site into a relay until the domain is blacklisted and the owner's ordinary business email stops arriving. And with no honeypot or rate limit, bots fill the inbox until nobody reads it. The fix persists the lead first, attempts delivery second, reports what actually happened, and strips CR/LF from anything reaching a header. The proof demonstrates the injection working — printing the forged headers — then shows the same input neutralised, across seventeen further attack vectors.

What you will learn

  • Understand email header injection, and why user input must never reach a mail header raw
  • Persist a lead before attempting delivery, and report success on what actually happened
  • Stop bots with a honeypot, a time check and a per-IP rate limit
  • Refuse javascript: URLs in admin-editable link fields
  • Log mail outcomes so a silent delivery failure is visible instead of invisible

Before you start

  • PHP basics, and having written a contact form before
  • PHP 8.1+ and MySQL 8 (or MariaDB 10.4+)
  • No Composer, no Node — deploys to cPanel shared hosting as files

New to PHP? The free PHP course covers everything this project assumes.

Academic integrity notice

These projects are provided for learning, experimentation and reference. Understand the code, modify it for your own requirements, and acknowledge external work according to your institution’s academic policies. Priodemy does not supply work to be submitted as your own.