Create Your PHP Contact Forms

Are you looking to take your website to the next level? Welcome to the world of PHP contact forms – the key to enhancing user engagement, collecting valuable data, and streamlining communication.
Follow our PHP contact form script tutorial below, or sign up for 123FormBuilder and build your contact form without coding. Get started for free!

Trusted by 35,000+ clients, from small businesses to large enterprises

Process Simple PHP Contact Form Data without Disruption

Contact forms are the easiest way to let your visitors get in touch with you. They also allow you to avoid revealing your email address online, which can attract spam.

Creating contact forms can be done with several scripting languages, although PHP stands out as one of the most widely used options. Its versatility allows for easy integration with databases, but its complex syntax can pose a challenge for those who are new to programming.

With the 123FormBuilder PHP generator, you get a jump-start by creating a fully functional PHP form script you can download and use without any PHP code knowledge.

To get the PHP contact form script for a simple contact form with the Submit button, simply click here and save the file, or copy the PHP contact form code from the window below.

Want to learn even more about PHP code? Check out our guide to building jQuery Contact forms with Ajax and PHP.

<?php

$action=$_REQUEST['action'];

if ($action=="") /** display the contact form */

{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}

else/* send the submitted data */

}
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill <a href=\"\">the form</a> again.";  
}
else
$from="From: $name\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("youremail@yoursite.com", $subject, $message, $from);
echo "Email sent!";
}
}

?>

How to Create a Form in PHP: Step-by-Step Tutorial

1. Create a PHP file

Use our PHP generator to create a PHP contact form with two parts: the form visitors see and the PHP script that processes the form data and sends it where you want it to go. 

Each part of the form can be located in the same file (as seen in the PHP example script) or in two different files. To create a PHP file, copy and paste the demo code above or download our example code file.

2. Copy the PHP script from above

To gather user data, we’ll create a simple PHP contact form that asks for a name, email, and message (see above). We’ve highlighted the PHP contact form code above to see how it works.

How the PHP Contact Form Works

Let’s test how your visitors see this PHP contact form and their fill-in experience.

When your visitors open the page with the form (see a live demo), they’ll see the form fields from the HTML code. 

After filling out the form and clicking the “Send Email” button, visitors will stay on the same page but see a message confirming the form was processed. 

Submitting the form sets a hidden parameter called “action” that prevents the form from being displayed again, so you won’t bother visitors with forms they’ve already filled out. 

The form also uses PHP validation to ensure that all the HTML form fields are filled in properly. If even one required field is left empty, it generates an error message.

Create Advanced Forms with Our PHP Form Builder

This page teaches you how to create a simple PHP contact form. As you can see, it’s a straightforward process for which you don’t really need to know how to code. 

If you want to gather more data with other types of fields, such as single-choice, multiple-choice, multiple pages, text box, a radio button, HTML tag, product, or dropdown fields, you’ll have to add validation and processing for these fields as well. 

However, learning how to build the perfect contact form is still manageable. And you don’t have to write the PHP form code — we generate it for you. As easily as 1-2-3!

Ensure Data Safety and Accuracy

When dealing with visitor information, it’s essential to ensure data safety. You wouldn’t want to fall prey to some scam or have the PHP form generator data stolen from your database through predatory activities. 

And there’s always the spam issue. If spammers start to autofill your contact form with garbage data, you can add CAPTCHA image verification to stop them, such as reCAPTCHA by Google. 

If users mistype their email addresses, turn on form validation to ensure all emails are correctly formatted. And if you want your visitors to send you files, you can let them upload files with PHP code, too. 

We have to say that 123FormBuilder is:

We employ extra security measures like SPF and DKIM to ensure your forms are safe and secure in a compliant environment. Add password protection and multi-factor authentication when dealing with sensitive information from visitors. 

Doing all of this on your own would require advanced knowledge of PHP. Luckily for you, the 123FormBuilder free PHP contact form generator includes these features and many more to make form building a breeze. Give it a try today!

Templates you can start with

Our platform provides form templates ready for customization with brand elements, conditional logic, and question branching.

Browse 2,000+ form templates

Build the perfect PHP forms for your website with 123FormBuilder PHP form creator.

Get started now