How Do Freelance Designers Add a PHP Contact Form?

For Freelance web designers · Based on Traversy PHP Contact Form Build

// TL;DR

Freelance web designers can add a working contact form to any portfolio site using PHP's native mail() function—no third-party service, no monthly fee. Build an HTML form with name, email, budget, and message fields, process submissions in a separate contact_form.php file, and deliver inquiries to your hosted email. If you use Gmail as your primary inbox, set up domain-level forwarding to relay messages automatically. This method works on any shared hosting plan and takes under 30 minutes to implement.

Why should freelance designers use a PHP contact form on their portfolio site?

A contact form is the most important conversion element on a freelance portfolio site. It removes the friction of visitors having to open their email client, copy your address, and compose a message. PHP's native mail() function lets you handle this entirely on your own hosting—no Formspree submissions limits, no EmailJS API keys, no monthly charges from third-party services.

The Traversy PHP Contact Form Build gives you a clean, repeatable method: your HTML form lives in index.php, the processing logic lives in contact_form.php, and the two are connected by the form's action attribute. This separation means you can redesign the form's appearance without touching the email logic.

How do you set up the form for client inquiries?

Start with four fields that cover what you need from every potential client:

- Name — ``

- Email — ``

- Project type or budget — ``

- Message — ``

Add a submit button with `name="submit"` — this exact name attribute is critical because the PHP processor checks for it with `isset($_POST['submit'])`. If the names don't match, no email will ever send.

Set the form tag to `

`. The method must be POST, not GET, to keep form data out of the URL.

How do you build the PHP processor for portfolio inquiries?

Create `contact_form.php` in your site's root folder. Inside, follow this exact sequence:

1. Gate with isset() — `if(isset($_POST['submit'])) { }` wraps everything. Without this, loading the file directly triggers errors.

2. Capture POST data — Assign each field to a variable: `$name = $_POST['name']`, `$subject = $_POST['subject']`, `$mail_from = $_POST['mail']`, `$message = $_POST['message']`.

3. Set the recipient — `$mail_to = 'you@yourdomain.com'`. This must be a hosted-domain email, not Gmail.

4. Build the From header — `$headers = 'From: ' . $mail_from;` ensures you see the potential client's email address when the inquiry lands in your inbox.

5. Format the message — `$txt = 'You have received a project inquiry from ' . $name . '.\n\n' . $message;` The double newline creates readable spacing.

6. Send and redirect — Call `mail($mail_to, $subject, $txt, $headers);` then immediately `header('Location: index.php?sent');`.

On index.php, check for `$_GET['sent']` and display a confirmation message like "Thanks! I'll get back to you within 24 hours."

What if you use Gmail as your main inbox?

PHP's mail() cannot deliver directly to Gmail—Google blocks these messages. The workaround is straightforward:

1. Keep `$mail_to` pointed at your hosted-domain mailbox (e.g., `contact@yourportfolio.com`).

2. Log into your hosting dashboard (cPanel, Plesk, etc.).

3. Navigate to email settings and create a forwarding rule from `contact@yourportfolio.com` to your Gmail address.

Every inquiry now arrives in your hosted mailbox and is automatically forwarded to Gmail. You reply from Gmail as usual.

What should you do next?

Upload both files to your live server, submit a test message, and check your hosted mailbox. If you see the email with the correct From address and formatted body, your form is working. Set up Gmail forwarding if needed, then style the form to match your portfolio design. The entire setup takes under 30 minutes and eliminates the need for any external form service on client projects going forward.

// FREQUENTLY ASKED QUESTIONS

Can I reuse this PHP contact form across multiple client projects?

Yes, the structure is fully reusable. Copy index.php and contact_form.php to each project, change the $mail_to variable to the client's hosted email address, and adjust the form fields and $txt greeting to match the project. The isset() gate, redirect pattern, and header construction stay identical every time.

Do I need a specific hosting provider for this to work?

Any shared hosting plan that supports PHP and has a configured mail transfer agent will work. Providers like SiteGround, Bluehost, HostGator, and A2 Hosting all support PHP mail() out of the box. Static hosts like Netlify or Vercel do not run PHP and cannot be used.

How do I add spam protection to a portfolio contact form?

Add Google reCAPTCHA to the HTML form and verify the token server-side in contact_form.php before calling mail(). Alternatively, add a honeypot field—a hidden input that bots fill out but humans don't. If the honeypot field contains data, skip the mail() call. Both methods work within the existing PHP processor structure.