Repository navigation
Expand file tree
/
Copy pathcontact-handler.php
More file actions
191 lines (162 loc) · 8.36 KB
/
Copy pathcontact-handler.php
File metadata and controls
191 lines (162 loc) · 8.36 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
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
<?php
// Suppress warnings so they don't break JSON output
error_reporting(0);
// Configuration
$to = 'info@jiggabyte.co.zm';
$subject = 'New Contact Form Submission from Jiggabyte Website';
// Check if form was submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get form data and sanitize
$name = isset($_POST['name']) ? strip_tags(trim($_POST['name'])) : '';
$email = isset($_POST['email']) ? filter_var(trim($_POST['email']), FILTER_SANITIZE_EMAIL) : '';
$service = isset($_POST['service']) ? strip_tags(trim($_POST['service'])) : 'General Enquiry';
$message = isset($_POST['message']) ? strip_tags(trim($_POST['message'])) : '';
// Validate required fields
$errors = [];
if (empty($name)) {
$errors[] = 'Name is required';
}
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = 'Valid email is required';
}
if (empty($message)) {
$errors[] = 'Message is required';
}
// If there are errors, return them
if (!empty($errors)) {
header('Content-Type: application/json');
echo json_encode([
'success' => false,
'message' => 'Please fix the following errors: ' . implode(', ', $errors)
]);
exit;
}
// ─────────────────────────────────────────────────────────────────────
// EMAIL TEMPLATE — Edit anything inside here to customise the email
// ─────────────────────────────────────────────────────────────────────
$email_content = "
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>New Enquiry — Jiggabyte Technology</title>
<style>
/* ── Global ── */
body { margin:0; padding:0; background:#f0f3f9; font-family: 'Segoe UI', Arial, sans-serif; }
table { border-collapse: collapse; }
/* ── Wrapper ── */
.wrapper { width:100%; background:#f0f3f9; padding: 40px 0; }
.card { max-width:600px; margin:0 auto; background:#ffffff;
border-radius:12px; overflow:hidden;
box-shadow: 0 8px 32px rgba(13,18,38,0.10); }
/* ── Header ── */
.header { background: linear-gradient(135deg, #0d1830 0%, #1a2f5e 100%);
padding: 36px 40px; text-align:center; }
.header h1 { margin:0 0 4px; color:#ffffff; font-size:22px;
font-weight:700; letter-spacing:-0.5px; }
.header p { margin:0; color:rgba(255,255,255,0.6); font-size:13px; }
/* ── Body ── */
.body { padding: 36px 40px; }
.intro { font-size:15px; color:#4b5675; margin:0 0 28px; line-height:1.6; }
/* ── Field rows ── */
.field { margin-bottom: 20px; padding: 16px 18px; background:#f7f9fd;
border-radius:8px; border-left: 3px solid #1a2f5e; }
.field-label { font-size:10px; font-weight:700; letter-spacing:0.12em;
text-transform:uppercase; color:#2d4f9e; margin-bottom:6px; }
.field-value { font-size:15px; color:#1a1f36; line-height:1.6; word-break:break-word; }
/* ── Message block ── */
.message-field { background:#f0f4ff; border-left-color:#2d4f9e; }
/* ── Footer ── */
.footer { background:#f7f9fd; padding: 22px 40px; text-align:center;
border-top:1px solid #e8edf5; }
.footer p { margin:4px 0; font-size:12px; color:#9aa3be; }
.footer strong { color:#6b7a99; }
</style>
</head>
<body>
<div class='wrapper'>
<table width='100%' cellpadding='0' cellspacing='0'>
<tr><td>
<div class='card'>
<!-- ══ HEADER — Edit the title and tagline below ══ -->
<div class='header'>
<img src='https://jiggabyte.co.zm/assets/logo_light.png' alt='Jiggabyte Logo' style='height: 48px; margin-bottom: 16px; display: inline-block;'>
<h1>New Website Enquiry</h1>
<p>Jiggabyte Technology Limited — jiggabyte.co.zm</p>
</div>
<!-- ══ BODY ══ -->
<div class='body'>
<!-- ══ Intro line — Edit this text ══ -->
<p class='intro'>
You have received a new message through your website contact form.
Reply directly to this email to respond to the enquiry.
</p>
<!-- Name -->
<div class='field'>
<div class='field-label'>Name</div>
<div class='field-value'>" . htmlspecialchars($name) . "</div>
</div>
<!-- Email -->
<div class='field'>
<div class='field-label'>Email Address</div>
<div class='field-value'>" . htmlspecialchars($email) . "</div>
</div>
<!-- Service -->
<div class='field'>
<div class='field-label'>Service of Interest</div>
<div class='field-value'>" . htmlspecialchars($service) . "</div>
</div>
<!-- Message -->
<div class='field message-field'>
<div class='field-label'>Message</div>
<div class='field-value'>" . nl2br(htmlspecialchars($message)) . "</div>
</div>
</div>
<!-- ══ FOOTER — Edit the footer text and branding below ══ -->
<div class='footer'>
<p><strong>Jiggabyte Technology Limited</strong></p>
<p>2337/M Off Leopards Hill Road, New Kasama, Lusaka, Zambia</p>
<p style='margin-top:12px;'>This message was sent via the contact form on jiggabyte.co.zm</p>
<p>Received: " . date('D, d M Y \a\t H:i T') . "</p>
</div>
</div>
</td></tr>
</table>
</div>
</body>
</html>
";
// ─────────────────────────────────────────────────────────────────────
// Set email headers
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// cPanel requires the From address to belong to the server domain to prevent spoofing rejection
$headers .= "From: Jiggabyte Website <noreply@jiggabyte.co.zm>" . "\r\n";
$headers .= "Reply-To: " . $name . " <" . $email . ">" . "\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
// Send email
if (mail($to, $subject, $email_content, $headers)) {
// Success response
header('Content-Type: application/json');
echo json_encode([
'success' => true,
'message' => 'Thank you for your message! We will get back to you soon.'
]);
} else {
// Error response
header('Content-Type: application/json');
echo json_encode([
'success' => false,
'message' => 'Sorry, there was an error sending your message. Please try again later.'
]);
}
} else {
// Not a POST request
header('Content-Type: application/json');
echo json_encode([
'success' => false,
'message' => 'Invalid request method.'
]);
}
?>