forked from smanek/aurora-pharmacy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontact.php
More file actions
105 lines (80 loc) · 4.46 KB
/
contact.php
File metadata and controls
105 lines (80 loc) · 4.46 KB
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
<?php
$strName = 'Homepage';
include_once "header.php";
?>
<div class="jumbotron">
<div class="container">
<h1>Contact Us</h1>
<p>We'll get back to you as soon as possible.<br />In case of emergency, call 911 immediately</p>
</div>
</div>
<div class="container">
<div class="row-fluid">
<div class="col-md-8 col-md-offset-2 centered">
<div class="well well-lg">
<h2>Contact Information</h2>
<table class="table-striped" width=100%>
<tr><td><p class="lead">Phone</p></td><td><a href="tel:+16308203360">(630) 820-3360</a></td></tr>
<tr><td><p class="lead">Fax</p></td><td><a href="tel:+16308206864">(630) 820-6864</a></td></tr>
<tr><td><p class="lead">Email</p></td><td><a href="mailto:contact@aurora-pharmacy.com">contact@aurora-pharmacy.com</a></td></tr>
<tr><td><p class="lead">Address</p></td><td><a href="https://www.google.com/maps/preview?q=475+N+Farnsworth+Ave,+Aurora,+IL&hl=en&ll=41.765406,-88.281133&spn=0.008819,0.01884&sll=39.739318,-89.266507&sspn=9.305214,19.291992&oq=475&hnear=475+N+Farnsworth+Ave,+Aurora,+Illinois+60505&t=m&z=16" target="_blank">475 N. Farnsworth Ave<br />Aurora, IL 60505</a></td></tr>
</table>
</div>
</div>
</div>
<div class="row-fluid">
<div class="col-md-8 col-md-offset-2 centered">
<?php
function cleanInput($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
function inputExists($data) {
return !is_null($data) && trim($data) != "";
}
function validateEmail($strData) {
return filter_var($strData, FILTER_VALIDATE_EMAIL);
}
function checkPhoneNumber($strData) {
$arr = array(); // old versions of php seem to require all three parameters
return (preg_match_all('/[0-9]/', $strData, $arr) >= 7);
}
$blnAttempted = $_SERVER["REQUEST_METHOD"] == "POST";
//count(array_intersect(array_keys($_POST), array('name','email','phone','message'))) !== 0;
// handle the form -- if it is good send emails, otherwise fill in whatever possible and flag error
if($blnAttempted && inputExists($_POST['username'])) {
//shut it down
echo '<div class="alert alert-success" role="alert"><h2>Thanks</h2><br /></div>';
} elseif($blnAttempted && inputExists($_POST['name']) && (validateEmail($_POST['email']) || checkPhoneNumber($_POST['phone'])) && inputExists($_POST['message'])) {
// do stuff. Send email, spit out 'thanks' message
$strMessage = "New message received!\n\n";
$strMessage .= "----------------------\n\n";
$strMessage .= "Name: " . cleanInput($_POST['name']) . "\n";
if(checkPhoneNumber($_POST['phone'])) $strMessage .= "Phone: " . cleanInput($_POST['phone']) . "\n";
if(validateEmail($_POST['email'])) $strMessage .= "Email: " . validateEmail($_POST['email']) . "\n";
$strMessage .= "Message: " . "\n\t" . wordwrap(cleanInput($_POST['message']), 75, "\n\t") . "\n";
$strSubject = "New Aurora Pharmacy Message";
$strHeaders = "From: contact@aurora-pharmac.com\n";
if(inputExists($_POST['email'])) $strHeaders .= "Reply-To: " . $_POST['email'] . "\n";
$blnSuccess = mail('contact@aurora-pharmacy.com', $strSubject, $strMessage, $strHeaders);
if(!$blnSuccess) {
mail('support@aurora-pharmacy.com', 'Aurora Pharmacy website failed to send message', $strHeaders . '\n\n' . $strSubject . '\n\n' . $strMessage);
}
if($blnSuccess) {
echo '<div class="alert alert-success" role="alert"><h2>Thanks</h2><br />You should hear back soon</div>';
} else {
echo '<div class="alert alert-info" role="alert"><h2>Something went wrong</h2><br />Sorry about that -- we had some trouble sending your message.<br />Please call or email the pharmacist directly<br />The webmaster has been notified of the issue</div>';
}
} else {
// return the form w/ notes where there's missing information iff attempted
include_once "form.php"; // uses $_POST and $blnAttempted
}
?>
</div>
</div> <!-- /row -->
</div> <!-- /container -->
<?php
include_once "footer.php";
?>