-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit.php
More file actions
109 lines (93 loc) · 3.11 KB
/
submit.php
File metadata and controls
109 lines (93 loc) · 3.11 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
<?php
require_once __DIR__ . '/config.php';
// Settings
$to = "support@rocketreception.ca";
$subject = "New Inquiry via Rocket Reception Website";
$postmarkToken = $postmarkToken ?? "";
$fromEmail = $postmarkFrom ?? "support@rocketreception.ca";
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405);
echo "Method not allowed.";
exit;
}
// Helper: basic sanitize
function clean_text($value) {
return strip_tags(trim((string)$value));
}
// Grab fields
$name = isset($_POST['name']) ? clean_text($_POST['name']) : '';
$emailRaw = isset($_POST['email']) ? trim((string)$_POST['email']) : '';
$email = filter_var($emailRaw, FILTER_VALIDATE_EMAIL);
$topic = isset($_POST['topic']) ? clean_text($_POST['topic']) : '';
$timeframe = isset($_POST['timeframe']) ? clean_text($_POST['timeframe']) : '';
$message = isset($_POST['message']) ? clean_text($_POST['message']) : '';
$source = isset($_POST['source']) ? clean_text($_POST['source']) : '';
// Optional honeypot (add a hidden field named "website" in your form)
$honeypot = isset($_POST['website']) ? clean_text($_POST['website']) : '';
if (!empty($honeypot)) {
http_response_code(200);
echo "Thanks! I'll get back to you shortly.";
exit;
}
// Required fields (match your current form)
if (!$name || !$email || !$message) {
http_response_code(400);
echo "Please include your name, a valid email, and a short message.";
exit;
}
// Prevent header injection
$safeReplyTo = str_replace(array("\r", "\n"), '', $email);
if (!$postmarkToken) {
http_response_code(500);
echo "Email service is not configured. Please email me directly at support@rocketreception.ca.";
exit;
}
// Build email body
$body = "You received a new message from Rocket Reception's contact form:\n\n";
$body .= "Name: {$name}\n";
$body .= "Email: {$email}\n";
if ($topic !== '') {
$body .= "What they want help with: {$topic}\n";
}
if ($timeframe !== '') {
$body .= "Timeframe: {$timeframe}\n";
}
if ($source !== '') {
$body .= "Source: {$source}\n";
}
$body .= "\nMessage:\n{$message}\n";
// Send via Postmark
$fromName = $name ? $name : "Rocket Reception";
$payload = array(
"From" => $fromName . " <" . $fromEmail . ">",
"To" => $to,
"Subject" => $subject,
"TextBody" => $body,
"ReplyTo" => $safeReplyTo
);
$ch = curl_init("https://api.postmarkapp.com/email");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/json",
"Content-Type: application/json",
"X-Postmark-Server-Token: " . $postmarkToken
));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
$resp = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlErr = curl_error($ch);
curl_close($ch);
if ($resp === false) {
http_response_code(500);
echo "Something went wrong. Please email me directly at support@rocketreception.ca.";
exit;
}
if ($httpCode >= 200 && $httpCode < 300) {
http_response_code(200);
echo "Thanks! I???ll get back to you shortly.";
} else {
http_response_code(500);
echo "Something went wrong. Please email me directly at support@rocketreception.ca.";
}
?>