-
Notifications
You must be signed in to change notification settings - Fork 1
/
contact.php
86 lines (65 loc) · 1.6 KB
/
contact.php
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
$myemail = "[email protected]";
/* inputs */
$yourname = check_input($_POST['yourname'], "Enter your name");
$subject = check_input($_POST['subject'], "Write a subject");
$email = check_input($_POST['email']);
$website = check_input($_POST['website']);
$type = check_input($_POST['type']);
$how_find = check_input($_POST['how']);
$comments = check_input($_POST['comments'], "Write your comments");
$t = time();
$timestamp = date("m/d/Y H:i:s",$t);
/* email field validation */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* email */
$message = "Hello!
Your contact form has been submitted by:
Name: $yourname
E-mail: $email
URL: $website
Type? $type
How did he/she find it? $how_find
Comments:
$comments
$timestamp";
$returnmessage = "Hello $yourname!
Your submission has been recieved.
Here is what you said:
$comments
Thank you for your feedback.
$timestamp";
/* send the email*/
mail($myemail, $subject, $message);
mail($email, $subject, $returnmessage);
/* Show success page */
header('Location: ./index.php');
exit();
/* Functions*/
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>