Cool PHP Contact Us!
Here you will make a simple but effective PHP Contact Us!
Here Is The Script With Explanation
Add this to your config.php
Code
function cleanvars($content){ //declare the cleanvars function
$content = mysql_real_escape_string($content);
$content = strip_tags($content); //strip html code
$content = addslashes($content); //addslashes to protect from possible SQL Injection
return $content; //return new content
} //end function
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
echo 'Contact Us'; //Title Goes Here
if(isset($_POST['contact'])) //if the form is posted
{
$name = cleanvars($_POST['name']); //These Check to see if the posts from the form are empty
$email = cleanvars($_POST['email']);
$subject = cleanvars($_POST['subject']);
$message = cleanvars($_POST['message']);
if(!isset($name))
{
echo 'Please enter your name'; //if there is no name in the form it displays the message
}
elseif(!isset($email))
{
echo 'Please enter your email'; //if there is no email in the form in the form it displays the message
}
elseif(!isset($subject))
{
echo 'Please enter the subject'; //if there is no subject in the form in the form it displays the message
}
elseif(!isset($message))
{
echo 'Please enter your message'; //if there is no message in the form in the form it displays the message
}
elseif($code = $_SESSION['key'])
{ } else {
mail('YOUR EMAIL GOES HERE', $subject, $message, 'FROM:'.$email); //the email that it will be sent to goes here, this also sends the email
echo 'Mail sent'; //This Message Shows Once The Message Is Sent Sucessfully.
}
}
else
{
echo '
<center>
<form method="post">
<table width="80%" border="0">
<tr>
<td width="30%"><b>Your Name</b></td>
<td width="70%"><input type="text" id="text_edit" name="name" /></td>
</tr>
<tr>
<td width="30%"><b>Your Email</b></td>
<td width="70%"><input type="text" id="text_edit" name="email" /></td>
</tr>
<tr>
<td width="30%"><b>Subject</b></td>
<td width="70%"><input type="text" id="text_edit" name="subject" /></td>
</tr>
<tr>
<td width="30%"><b>Message</b></td>
<td width="70%"><textarea id="text_edit" name="message"></textarea></td>
</tr>
<tr>
<td width="30%"></td>
<td width="70%"><input type="submit" name="contact" id="text_edit" value="Contact Us" /></td>
</tr>
</table>
</form>
</center>'; //This Is A Simple PHP HTML Form, No Need For Explaining If You Need Explaining Just Send Me A Message
}
echo '</div>';
?>
If You Need Help Just Ask!