nightscream
New Member
- Messages
- 948
- Reaction score
- 0
- Points
- 0
Ok lets create a simple contact form.
First create a .php file, You can choose the name.
First we create the php part.
Now lets get to the form part.
create a form something like this.
because we put our action in the same file we have to put the thing below in it so the file knows it has to execute the php in the same file.
I hope you'll understand everything
Made by nightscream
First create a .php file, You can choose the name.
First we create the php part.
Code:
<?php
if (isset( $_POST['Send'] )) { // Check if Submit button is Clicked
// Get data from Form
// This are sescriptions of the variables the script uses
$Name = $_POST['Name']; // 'Name' is equal to name="Name" in the fuction <input> from the form.
$Email = $_POST['Email']; // 'Email' is equal to name="Email" in the fuction <input> from the form.
$Subject = $_POST['Subject']; // 'Subject' is equal to name="Subject" in the fuction <input> from the form.
$Msg = $_POST['Msg']; // 'Message' is equal to name="Message" in the fuction <input> from the form.
// A sort of spam control to see if every field is filled in
if ((empty($Name)) || (empty($Email)) || (empty($Subject)) || (empty($Msg))) {
echo "You must enter in all fields.<br />";
if (empty($Name)) { // If name is empty
echo "You must enter your name.<br />";
}
if (empty($Email)) { // If email is empty
echo "You must enter your email.<br />";
}
if (empty($Subject)) { // If email is empty
echo "You must enter your subject.<br />";
}
if (empty($Msg)) { // If message is empty
echo "You must enter your message.<br />";
}
die();
}
// Format the message a bit to get the form style
$Message = "Name: $Name\nEmail: $Email\nMessage: $Msg";
// Put the email adres where the contact form should be sended to.
$ContactEmail = "iwek6a8@iwek.x10hosting.com";
// Send the email to the $ContactEmail
mail( $ContactEmail, $Subject, $Message, "From: $Email" );
// It will send an email back to the one who sended the message
// this is the thank you message
$rMessage = "
--- Your information ---\n
Name: $Name\n
Email: $Email\n
Message: $Msg\n
--- Please do not reply ---\n\n
Thank you for contacting us, we will get back to you as soon as possible!
";
mail( $Email, "Re: $Subject", $rMessage, "Reply: $ContactEmail" );
echo 'Thank you for Contacting us.<br />
We will get back to you in 24 hours';
}
?>
Now lets get to the form part.
create a form something like this.
Code:
<form name="Contact" action="<? $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" method="post">
<table width="300" cellpadding="0" cellspacing="3">
<tr>
<td>Name:</td>
<td><input name="Name" type="text" size="30"></td>
</tr>
<tr>
<td>Email:</td>
<td><input name="Email" type="text" size="30"></td>
</tr>
<tr>
<td>Subject:</td>
<td><input name="Subject" type="text" size="30"></td>
</tr>
<tr>
<td valign="top">Message:</td>
<td><textarea cols="30" rows="6" name="Msg"></textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Send" name="Send"> <input type="reset" value="Clear" name="reset"></td>
</tr>
</table>
</form>
Code:
<? $_SERVER['PHP_SELF']; ?>
I hope you'll understand everything
Made by nightscream