Web Hosting Knowledge Base

Knowledge Base » General Information » How to create an example contact form?6 min read

How to create an example contact form?6 min read

In this tutorial, we are going to demonstrate how to set up a working PHP contact form in your AwardSpace web hosting account.

Each contact form consists of two components: the actual form and the PHP mailer script that processes the information and sends an email. Setting up a PHP contact form on a web server is a three-step process:

  1. Registering an e-mail account;
  2. Creating an HTML form;
  3. Creating a PHP script.


Step #1: Registering an Email Address

The very first step is to create an e-mail account on your server. Our mail server requires authentication in order to send emails out. Therefore, by using one of the emails that exist in your Hosting Control Panel as a sender (from address), you will be able to authenticate yourself and the server will be able to deliver the message to the specified recipient address.

Detailed information on how to set up an e-mail address in your AwardSpace account can be found on our How to create an email account? page.


Step #2: Creating an HTML Form

Add a new HTML file to your website’s root directory (e.g. contact.html) and insert the following code into it:


             Contact form
             <font size="5">
             <b>Contact form</b>
             <form method="POST" action="mailer.php">
                 <input type="text" name="subject" size="20">
                 <input type="text" name="name" size="20">
                 <input type="email" name="email" size="20">
                 <textarea rows="9" name="message" cols="30">
                 <input type="submit" value="Send" name="submit">


Save the changes you’ve made and proceed to the next step.


Step #3: Creating a PHP Mailer Script

Upload an empty PHP file to your server with the name of mailer.php, and place it next to your contact.html file.

Double-click on the document you’ve uploaded, and copy and paste the below script into it:


     if(isset($_POST['submit'])) {
         $myemail = 'youremail@yourdomain.com';
         $subject = $_POST['subject'];
         $name = $_POST['name'];
         $email = $_POST['email'];
         $message = $_POST['message'];
         $headers = 'From: Contact Form <$myemail>\r\n';
         $headers .= 'Reply-To: $name <$email>\r\n';
         echo 'Your message has been sent successfully!';
         mail($myemail, $subject, $message, $headers);
     } else {
         echo 'An error has occurred!';


Note: Make sure you replace youremail@yourdomain.com with a valid e-mail address created through our system.


Now that you’ve followed the above instructions, it is time to test your contact form’s functionality.

To see if your contact form is capable of sending messages, open your HTML document in a browser. Fill in the appropriate fields and click Send:

contact form 1  

After you submit the information to the server, the mailer.php script will return either a positive or negative response.

If the test is successful, your browser will display a Your message has been sent successfully! message.

contact form 2

AwardSpace on Social Media

It's Time to Share Your Story.

Get Free Web Hosting. Start a website, and introduce yourself to the world.

Share This

Share This

Share this post with your friends!