PHP is open source scripting language. It\'s widely used to develop web applications.  Home Web Programming PHP Simple Contact Form
Your Ad Here

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.



Author's URL: Valuedresource.com
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
print this page subscribe to newsletter subscribe to rss

Web programming � everything from the basics of visual design and architecture to the specifics of applications, graphics, and scripting. More Web Programming: Most Popular Materials | Fresh Materials | More PHP Tutorials at LearnPHP.org

Add comments to "Simple Contact Form"

Only registered users can write comment

No comments yet...