forked from kisanjong/rotalabutterfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact-form.php
130 lines (119 loc) · 5.18 KB
/
contact-form.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
$subjectPrefix = '[contact@rotalabutterfly.com]';
$emailTo = 'contact@rotalabutterfly.com';
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = stripslashes(trim($_POST['form-name']));
$email = stripslashes(trim($_POST['form-email']));
$subject = stripslashes(trim($_POST['form-subject']));
$message = stripslashes(trim($_POST['form-message']));
$pattern = '/[\r\n]|Content-Type:|Bcc:|Cc:/i';
if (preg_match($pattern, $name) || preg_match($pattern, $email) || preg_match($pattern, $subject)) {
die("Header injection detected");
}
$emailIsValid = preg_match('/^[^0-9][A-z0-9._%+-]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/', $email);
if($name && $email && $emailIsValid && $subject && $message){
$subject = "$subjectPrefix $subject";
$body = "Name: $name <br /> Email: $email <br /> message: $message";
$headers = 'MIME-Version: 1.1' . PHP_EOL;
$headers .= 'Content-type: text/html; charset=utf-8' . PHP_EOL;
$headers .= "From: $name <$email>" . PHP_EOL;
$headers .= "Return-Path: $emailTo" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "X-Mailer: PHP/". phpversion() . PHP_EOL;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
} else {
$hasError = true;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-2">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">Rotala Butterfly</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-2">
<ul class="nav navbar-nav">
<li><a href="index.html">Nutrient Calculator</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="glossary.html">Glossary</a></li>
<li class="active"><a href="contact-form.php">Contact</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="page-header">
<h1>Contact Us</h1>
</div>
</div>
</div>
<?php if(!empty($emailSent)): ?>
<div class="col-md-6 col-md-offset-3">
<div class="alert alert-success text-center">Your message has been sent successfully.</div>
</div>
<?php else: ?>
<?php if(!empty($hasError)): ?>
<div class="col-md-5 col-md-offset-4">
<div class="alert alert-danger text-center">There was an error sending , try again later.</div>
</div>
<?php endif; ?>
<div class="col-md-6 col-md-offset-3">
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" id="contact-form" class="form-horizontal" role="form" method="post">
<div class="form-group">
<label for="name" class="col-lg-2 control-label">Name</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="form-name" name="form-name" placeholder="Name" required>
</div>
</div>
<div class="form-group">
<label for="email" class="col-lg-2 control-label">Email</label>
<div class="col-lg-10">
<input type="email" class="form-control" id="form-email" name="form-email" placeholder="Email" required>
</div>
</div>
<div class="form-group">
<label for="subject" class="col-lg-2 control-label">Subject</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="form-subject" name="form-subject" placeholder="subject" required>
</div>
</div>
<div class="form-group">
<label for="message" class="col-lg-2 control-label">Message</label>
<div class="col-lg-10">
<textarea class="form-control" rows="3" id="form-message" name="form-message" placeholder="message" required></textarea>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button type="submit" class="btn btn-default">Send</button>
</div>
</div>
</form>
</div>
<?php endif; ?>
<!--[if lt IE 9]>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<![endif]-->
<!--[if gte IE 9]><!-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<!--<![endif]-->
<script src="js_build/bootstrap.js"></script>
<script type="text/javascript" src="js_build/contact-form.js"></script>
</body>
</html>