Tip:
Highlight text to annotate it
X
Welcome, my name is Jeff. I'm going to teach you how to create a basic PHP contact form.
You can find this article by going to our website cloudymouse.com. The article you are
looking for is How to Create a Basic PHP Contact Form. We'll start with the HTML part of it.
Creating the contact form. Now, there is going to be an opening and closing form tag. That
is what houses the entire form. Inside of that you are going to have different input
fields and also a textarea. Now, there is three different properties inside the first
form tag. The only that you need to worry about is the action property. This tells us
where the PHP file is going to send the data. And next are the input fields, these are how
users are going to submit data. Each input field will have a type and a name. The name
is how the PHP file is going to reference the data that the user submitted. So, for
example, we have name, email, and comments. The textarea tag also has a closing tag, but
the input tags don't. You also need to set the rows and columns for the textarea. This
one is set for 5 rows and 15 columns. Each of the input fields has a type. In this example,
we used text, that is the standard text box that you see on most contact forms. Other
than that there is also button, checkbox, date, email, file, image, password, a lot
of different options there. And then, here you can see an example of that contact form
that we had up there. Down at the bottom we have the reset form and submit form buttons. Now for the PHP file. This is going
to be the minimum PHP coding that you are going to need to send the basic contact form.
If you want to add other security to prevent spam, there are other verification methods
that you can add, we'll discuss those in another lesson. The main thing that we are setting right here
is the variables. As you can see, there is $Name, $Email, and $Message. And each of these
is grabbing information from the contact form, where we set the different input fields with
name=name, name=email, name=comments. Then here is where we are grabbing it, with $_POST['name'].
This next section is formatting that information. For the body of the email that it is going
to send to whatever email address you specify. Then we got the line of code that actually
sends the email to your email address. In this example, we got youremail@example.com.
You'll change that to your email address. Then we have the subject line that is going
to show up in the email. We have Basic Contact Form, you'll change that to whatever you want
it to be. Then there is, who it is from. We've got Cloudy Mouse Blog, you'll change that
to the name of your website. At the bottom, we have the redirect, this is going to where
you send the user after they submit the form. So, you've got the contact form done in your
HTML page or PHP if you're using PHP. Then you have the PHP file that actually sends
the contact information. The last thing that you are going to want to check is the permissions
of the PHP file. By default, most PHP files and other files are going to be set to 6-6-6.
You are going to want it to read 6-4-4. Otherwise, people trying to send the form will get a
server error when they hit submit. And that's it. Create the form in HTML on your webpage.
And then create a PHP file to send the information.