-
Notifications
You must be signed in to change notification settings - Fork 116
/
contact.php
201 lines (179 loc) · 6.92 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php require_once('header.php'); ?>
<?php
$statement = $pdo->prepare("SELECT * FROM tbl_page WHERE id=1");
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row) {
$contact_title = $row['contact_title'];
$contact_banner = $row['contact_banner'];
}
$statement = $pdo->prepare("SELECT * FROM tbl_settings WHERE id=1");
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row) {
$contact_map_iframe = $row['contact_map_iframe'];
$contact_email = $row['contact_email'];
$contact_phone = $row['contact_phone'];
$contact_address = $row['contact_address'];
}
?>
<div class="page-banner" style="background-image: url(assets/uploads/<?php echo $contact_banner; ?>);">
<div class="inner">
<h1><?php echo $contact_title; ?></h1>
</div>
</div>
<div class="page">
<div class="container">
<div class="row">
<div class="col-md-12">
<h3>Contact Form</h3>
<div class="row cform">
<div class="col-md-8">
<div class="well well-sm">
<?php
// After form submit checking everything for email sending
if(isset($_POST['form_contact']))
{
$error_message = '';
$success_message = '';
$statement = $pdo->prepare("SELECT * FROM tbl_settings WHERE id=1");
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row)
{
$receive_email = $row['receive_email'];
$receive_email_subject = $row['receive_email_subject'];
$receive_email_thank_you_message = $row['receive_email_thank_you_message'];
}
$valid = 1;
if(empty($_POST['visitor_name']))
{
$valid = 0;
$error_message .= 'Please enter your name.\n';
}
if(empty($_POST['visitor_phone']))
{
$valid = 0;
$error_message .= 'Please enter your phone number.\n';
}
if(empty($_POST['visitor_email']))
{
$valid = 0;
$error_message .= 'Please enter your email address.\n';
}
else
{
// Email validation check
if(!filter_var($_POST['visitor_email'], FILTER_VALIDATE_EMAIL))
{
$valid = 0;
$error_message .= 'Please enter a valid email address.\n';
}
}
if(empty($_POST['visitor_message']))
{
$valid = 0;
$error_message .= 'Please enter your message.\n';
}
if($valid == 1)
{
$visitor_name = strip_tags($_POST['visitor_name']);
$visitor_email = strip_tags($_POST['visitor_email']);
$visitor_phone = strip_tags($_POST['visitor_phone']);
$visitor_message = strip_tags($_POST['visitor_message']);
// sending email
$to_admin = $receive_email;
$subject = $receive_email_subject;
$message = '
<html><body>
<table>
<tr>
<td>Name</td>
<td>'.$visitor_name.'</td>
</tr>
<tr>
<td>Email</td>
<td>'.$visitor_email.'</td>
</tr>
<tr>
<td>Phone</td>
<td>'.$visitor_phone.'</td>
</tr>
<tr>
<td>Comment</td>
<td>'.nl2br($visitor_message).'</td>
</tr>
</table>
</body></html>
';
$headers = 'From: ' . $visitor_email . "\r\n" .
'Reply-To: ' . $visitor_email . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: text/html; charset=ISO-8859-1\r\n";
// Sending email to admin
mail($to_admin, $subject, $message, $headers);
$success_message = $receive_email_thank_you_message;
}
}
?>
<?php
if($error_message != '') {
echo "<script>alert('".$error_message."')</script>";
}
if($success_message != '') {
echo "<script>alert('".$success_message."')</script>";
}
?>
<form action="" method="post">
<?php $csrf->echoInputField(); ?>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" name="visitor_name" placeholder="Enter name">
</div>
<div class="form-group">
<label for="email">Email Address</label>
<input type="email" class="form-control" name="visitor_email" placeholder="Enter email address">
</div>
<div class="form-group">
<label for="email">Phone Number</label>
<input type="text" class="form-control" name="visitor_phone" placeholder="Enter phone number">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="name">Message</label>
<textarea name="visitor_message" class="form-control" rows="9" cols="25" placeholder="Enter message"></textarea>
</div>
</div>
<div class="col-md-12">
<input type="submit" value="Send Message" class="btn btn-primary pull-right" name="form_contact">
</div>
</div>
</form>
</div>
</div>
<div class="col-md-4">
<legend><span class="glyphicon glyphicon-globe"></span> Our office</legend>
<address>
<?php echo nl2br($contact_address); ?>
</address>
<address>
<strong>Phone:</strong><br>
<span><?php echo $contact_phone; ?></span>
</address>
<address>
<strong>Email:</strong><br>
<a href="mailto:<?php echo $contact_email; ?>"><span><?php echo $contact_email; ?></span></a>
</address>
</div>
</div>
<h3>Find Us On Map</h3>
<?php echo $contact_map_iframe; ?>
</div>
</div>
</div>
</div>
<?php require_once('footer.php'); ?>