Marketing x Data

Contact Form without Third-party Services

Contact form email delivery


Summary

Many websites rely on paid platforms like Mailchimp or SendGrid to handle contact form emails. But for a simple enquiry form, those services are not necessary. With an open-source PHP library and a free Google account, a website can send email directly through Google's mail servers at no ongoing cost.

The problem with third-party email services

Platforms like Mailchimp, SendGrid, and Postmark are excellent tools for sending newsletters or large volumes of transactional email. However, for a basic contact form that receives occasional enquiries, they introduce unnecessary complexity and monthly costs. Many of these platforms also have free tiers with strict limits, and they often require API key management, verified domains, and account setup that goes well beyond what a simple contact form actually needs.

The question is: can a website send email without any of that? The answer is yes, and it comes down to understanding how email delivery actually works.

How email delivery works

When you send an email from Gmail or Outlook, your mail client connects to an SMTP server (Simple Mail Transfer Protocol) and hands off the message. That server then handles delivery to the recipient. This same mechanism is available to any application that can speak the SMTP protocol — including a PHP script running on a web server.

Google's mail infrastructure is available as an SMTP relay for any Gmail or Google Workspace account. This means a website can authenticate with Google's servers using a Google account and send email through them, piggybacking on the same reliable delivery infrastructure that powers Gmail.

The stack: PHPMailer and a Google App Password

PHPMailer is a free, open-source PHP library that handles the SMTP protocol so you do not have to write low-level connection code yourself. It is installed via Composer, the standard PHP package manager, and requires no subscription or account. The library has been maintained for over twenty years and is one of the most widely used PHP libraries in existence.

On the Google side, rather than using your main account password directly, Google allows you to generate an App Password — a separate credential scoped specifically to third-party applications. This is safer than sharing your main password, and it can be revoked at any time without affecting your Google account. The App Password is stored as an environment variable on the server, keeping it out of the codebase.

How the contact form works end to end

When a visitor fills in the contact form and clicks submit, the following happens:

  1. The browser sends a POST request to a PHP script on the server, carrying the form fields such as name, email, business, and message.
  2. PHP reads the form data and passes it to PHPMailer, which opens an authenticated SMTP connection to Google's mail servers on port 465 using SSL encryption.
  3. PHPMailer authenticates with Google using the App Password and hands off the email. Google then delivers it to the recipient inbox.
  4. A reply-to address is set to the visitor's email, so replying to the notification goes directly back to them rather than bouncing off the sender address.
  5. A Slack notification can also be sent via a webhook, so enquiries appear in a Slack channel in real time alongside the email.
  6. The visitor sees thank you message or is redirected to a confirmation page on success, or an error page if something went wrong.
Why this does not cost anything

There are three components in this setup: the PHP server, the PHP library, and Google's SMTP service. PHPMailer is open-source and free. Google's SMTP relay is available to any Gmail account at no charge, with a daily sending limit of 500 emails — more than enough for a contact form. The PHP server is whatever hosts the website, which is already a fixed cost.

There is no email platform account, no API key subscription, no transactional email pricing tier, and no vendor dependency. The only requirement is a Google account and a few environment variables set on the server.

When this approach makes sense

This setup is well-suited for low-volume contact forms, enquiry pages, and notification emails where the volume is predictable and modest. It is not designed for sending newsletters to large lists or high-volume transactional email such as order confirmations at scale. For those use cases, a dedicated email delivery service is worth the cost.

But for a marketing or portfolio website where the goal is simply to receive enquiries without adding external dependencies, PHPMailer with Google SMTP is a clean, reliable, and cost-free solution that gives you full control over the delivery logic.

Available Resources