Simple Contact Form

Simple Contact FormIn order for you to write up your own contact form you must make the following files:

contact.php
contactsent.php

Now open up the contact.php page and place the following code inside it.

Code:

<form action="contactsent.php" method="post">
Name: <input type="text" name="name">
<br>
E-mail: <input type="text" name="email">
<br>
Message: <br> <textarea name="message" cols="50" rows="5"></textarea>
<br>
<input type="submit" value="Submit">
</form>

This code is the form. It well allow your guest to fill in there name and email address along with there message. Once you have added that code you can save and close that page.

Now open up contactsent.php and put in the following php code.

Code:

<?php
$name=$_POST['name'];
$email=$_POST['email'];
$message=$_POST['message'];
$to="your email address here";
$message="Name: $name n E-mail: $email n Comments: $comments n";
if(mail($to,"Contact from your site",$message,"From: $emailn")) {
echo "Thank you, your email has been send.";
} else {
echo "Sorry but there is an error. Try again please.";
}
?>

This code is very simple but hard to under stand if you've never seen anything like it so we are going to break it down for you.

$name=$_POST['name'];
$email=$_POST['email'];
$message=$_POST['message'];

This part of the code grabs all the information from the contact form.

$message="Name: $name n E-mail: $email n Comments: $comments n";

Then the code above will place the information into an email and the n part makes it so each part has its own line to make it nice and clean for you to read.

if(mail($to,"Contact from your site",$message,"From: $emailn")) {
echo "Thank you, your email has been send.";
}

Then if the message is a success the above code it will send the email on to you and say thanks to the guest and tell them that the email has been sent threw.

else {
echo "Sorry but there is an error. Try again please.";
}

But if for some reason the email does not send threw the next part of the code will kick in and tell the guest that there is an error and if they would please try again.

That's it your all done.


Related Articles

  • How to make a simple form mailer with PHP
    As you may be well aware, displaying your e-mail address on your website can lead to e-mail harvesters picking up your address and adding it to hundreds or even thousands of lists used by spammers...
  • The Importance of Having a Feedback Form in Your E-commerce Website
    Internet marketing is a different ball game altogether when compared to traditional marketing. A brick and mortar store employs salespersons to guide and advise its customers. No such equivalent of a salesperson exists for an online store. This could be one of the reasons why people shy away from on...
  • PHP Contact Form
    First, lets create the html section. I made a simple form, but it gets the job done. You can customize it if you want, but remember to use the same form variables.
  • Form Handling
    We are going to be working with the $_Post or $_Get arrays. They basically tell the form if i needs to post something, or get something. In this case we are going to be showing you the basics of a contact email form, so we will be using the $_Post array.
  • Form Email
    Learn to send mail with the php mail(); function.
  • Contact Form
    Here I will explain to you how you can create a simple contact form. The form will collect data from the visitor and send it to any email address you please. The only requirement for this tutorial is for you to have .php enabled on your server. If you dont want to read through the whole tutorial a....
  • E-mail form using HTML and PHP
    Sometimes its a nice touch to include an e-mail feedback form on your contact page or elsewhere on your web site. Lets create an e-mail form using html and a simple php script to send it along.
  • Good 24/7 Hosting Customer Support -- Is It Possible?
    Even if you are an experienced webmaster you will need to contact the support team time from time in order to solve problems which can be either on your side or web hosting company side...
  • How to Implement the CAPTCHA with PHP and GD
    This article is a gas, it will show you How to Implement the CAPTCHA with PHP and GD. All the necessary code is laid out nice and neat by the author who has also provided you with helpful graphics to make it easy to understand.
  • Making the Sale When the Customer Won't Buy
    Ever had a party online or offline, and had guests say I love that item, but I cant afford it right now, or Its so hard to decide, I want all of this!. This is a perfect time to sell all those items to your customer without them having to pay a dime.

Contact Web Design Outsource and get started today

Need Website Designing, Development, Redesigning, Maintenance and SEO services or help growing your company's web presence? Request a free Quote Now.