Build an HTML form that posts its fields to a PHP script, which reads them from $_POST, validates them and calls mail(). Upload both files to your public web folder. The hosting platform requires mail() to carry a fifth parameter of -f plus a real address on your domain, or messages fail to send. Add Google reCAPTCHA, because spam sent through an unprotected form can get an account suspended.
Contact forms allow visitors to reach you without exposing your email address to spam bots. A PHP contact form processes submissions on your server and sends messages directly to your inbox.
You will create a basic PHP contact form, configure the mail headers correctly for our hosting environment and add spam protection. Once complete, visitors can submit enquiries through your website.
You need two files: an HTML form that visitors see and a PHP script that processes submissions. The HTML file collects information whilst the PHP file validates input and sends the email.
action attribute should point to your PHP processing script and the method should be set to POST.$_POST, validates the input and constructs an email message. This PHP contact form tutorial provides a complete working example you can adapt..php extension.Your basic contact form structure is now in place. Next, you need to configure the mail headers correctly for our hosting environment.
Our hosting platform requires a valid sender address in the mail function. Without this configuration, your form submissions will fail to send.
mail() function. It typically looks like mail($to,$subject,$message,$headers);-f parameter with a valid email address configured on your domain. The updated line should read: mail($to,$subject,$message,$headers,'-f your@email.here'); replacing your@email.here with an actual email address from your domain.Your contact form now sends emails correctly through our mail servers. The sender address you specified must exist on your domain for the form to work.
Unsecured contact forms are a common target for spam bots. Attackers exploit vulnerable forms to send thousands of spam emails, which can lead to your hosting account being suspended for excessive mail usage.
Add Google reCAPTCHA to your contact form. This verification system blocks automated submissions whilst allowing legitimate visitors to contact you. Our spam detection systems monitor outgoing mail across all hosting accounts, and forms that generate spam traffic risk suspension.
Your PHP contact form is now configured and protected. You created the form structure, configured mail headers for our hosting environment and added spam protection. Visitors can now submit enquiries through your website.
Test your form by submitting a message and checking that it arrives in your inbox. If you use WordPress, consider our WordPress contact form guide for plugin-based alternatives that include built-in spam protection.
If you run into any trouble, get in touch and our team will be happy to help.
Did this guide solve your problem?
Our UK support team answers tickets and live chat every day. Send us the guide you were following and where it stopped working.
Related guides
cPanel hosting with the tools these guides use, backed by UK support.
Get cPanel HostingProtect your visitors with SSL certificates – from budget DV to premium EV certificates.
Get SSL Certificate