Contact Information

Simple PHP Contact Forms

If you ever wanted to have simple contact forms for your website, you have come to the right place. This very easy to use script will e-mail you the results of the contact form. It is very flexible, and simple to insert on your website.

Overview of Method & Requirements

For this script to work correctly, your host must allow you to use PHP on your website, and the file for the script needs to end in .php

A neat feature about this form, is that an e-mail will only be sent when the information on the form is correct, if it is not correct, an error will be displayed and an e-mail will not be sent.

Explanation of Script

At the bottom you will be able to see the full script so you can understand the structure.

The beginning of the script, we declare values, these are the values that are on the contact form (First name, Last name, E-mail Address, Phone number, Website, etc.)

Each input box must include the name attribute.

This is correct: <input type="text" name="FirstName" size="20" />

This is incorrect: <input type="text" size="20" />

The name attribute for this particular text box is named FirstName. Earlier I mentioned the script will declare values, it will take the value from the text box FirstName, and assign it a certain variable.

For example, the text box with the name FirstName, would be declared like this: $contact_firstname = $_POST['FirstName'];

$contact_firstname is the name of the variable, and FirstName was the name of the text box on your form. If you entered Billy for your First name, $contact_firstname would be equal to Billy.

We use the same exact logic to add the other text boxes, such as Last name, E-mail address, etc.

The e-mail address that the form is sent to, is declared on the line that reads: $to = 'user@mydomain.com';

Likewise, the subject is declared on this line: $subject = "Message submitted using Contact Us form";

All of the above values including the $message can be configured to whatever value you wish to use. The message is on the line below the to address, and that line reads: