-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontact.php
More file actions
138 lines (129 loc) · 5.86 KB
/
contact.php
File metadata and controls
138 lines (129 loc) · 5.86 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Contact Administration</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: #f4f6f8;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.contact-container {
background: white;
padding: 2rem 3rem;
border-radius: 12px;
box-shadow: 0 8px 24px rgba(0,0,0,0.1);
max-width: 500px;
width: 100%;
text-align: center;
}
h1 {
margin-bottom: 1rem;
color: #333;
}
p {
font-size: 1.1rem;
color: #555;
}
a {
color: #2575fc;
text-decoration: none;
font-weight: 600;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<?php
session_start();
include "connection.php";
$success_message = "";
$error_message = "";
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['send_message'])) {
$name = trim($_POST['name'] ?? '');
$email = trim($_POST['email'] ?? '');
$phone = trim($_POST['phone'] ?? '');
$message = trim($_POST['message'] ?? '');
$staff_email = "booker.library@gmail.com";
if (empty($name) || empty($email) || empty($message)) {
$error_message = "Name, email, and message are required.";
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error_message = "Invalid email format.";
} else {
// Save message to database (optional)
$stmt = $db->prepare("INSERT INTO contact_messages (name, email, phone, message, staff_email, submitted_at) VALUES (?, ?, ?, ?, ?, NOW())");
if ($stmt) {
$stmt->bind_param("sssss", $name, $email, $phone, $message, $staff_email);
if ($stmt->execute()) {
// Send email to staff
$subject = "New Contact Message from " . $name;
$headers = "From: " . $name . " <" . $email . ">\r\n";
$headers .= "Reply-To: " . $email . "\r\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
$email_message = "You have received a new message from the contact form.\n\n";
$email_message .= "Name: $name\n";
$email_message .= "Email: $email\n";
$email_message .= "Phone: $phone\n";
$email_message .= "Message:\n$message\n";
require_once 'phpmailer_setup.php';
$sent = sendEmail($staff_email, $subject, $email_message, $email);
if ($sent) {
$success_message = "Your message has been sent to the administration.";
} else {
$error_message = "Failed to send your message via email.";
}
} else {
$error_message = "Failed to send your message: " . $stmt->error;
}
$stmt->close();
} else {
$error_message = "Failed to prepare message submission: " . $db->error;
}
}
}
?>
<div class="contact-container">
<h1>Contact Administration</h1>
<p>If you are not in our system, please contact the administration for assistance.</p>
<?php if ($success_message): ?>
<div style="color: green; margin-bottom: 1rem;"><?php echo htmlspecialchars($success_message); ?></div>
<?php endif; ?>
<?php if ($error_message): ?>
<div style="color: red; margin-bottom: 1rem;"><?php echo htmlspecialchars($error_message); ?></div>
<?php endif; ?>
<form method="POST" action="contact.php" novalidate>
<input type="hidden" name="send_message" value="1" />
<div style="margin-bottom: 1rem;">
<label for="name">Name *</label><br />
<input type="text" id="name" name="name" required style="width: 100%; padding: 8px; border-radius: 6px; border: 1px solid #ccc;" />
</div>
<div style="margin-bottom: 1rem;">
<label for="email">Email *</label><br />
<input type="email" id="email" name="email" required style="width: 100%; padding: 8px; border-radius: 6px; border: 1px solid #ccc;" />
</div>
<div style="margin-bottom: 1rem;">
<label for="phone">Phone</label><br />
<input type="tel" id="phone" name="phone" style="width: 100%; padding: 8px; border-radius: 6px; border: 1px solid #ccc;" />
</div>
<div style="margin-bottom: 1rem;">
<label for="message">Message *</label><br />
<textarea id="message" name="message" rows="6" required style="width: 100%; padding: 8px; border-radius: 6px; border: 1px solid #ccc;"></textarea>
</div>
<div style="margin-bottom: 1rem;">
<label for="staff_email">To (Staff Email)</label><br />
<input type="email" id="staff_email" name="staff_email" value="booker.library@gmail.com" readonly style="width: 100%; padding: 8px; border-radius: 6px; border: 1px solid #ccc; background-color: #eee;" />
</div>
<button type="submit" style="background-color: #2575fc; color: white; padding: 12px 20px; border: none; border-radius: 8px; cursor: pointer; font-weight: 600; width: 100%;">Send Message</button>
</form>
<p style="margin-top: 1rem;"><a href="student_login.php">Back to Login</a></p>
</div>
</body>
</html>