-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontact_handler.php
More file actions
69 lines (58 loc) · 2.17 KB
/
Copy pathcontact_handler.php
File metadata and controls
69 lines (58 loc) · 2.17 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
<?php
require_once 'config/database.php';
class ContactHandler {
private $conn;
private $table = "contact_messages";
public function __construct() {
$database = new Database();
$this->conn = $database->getConnection();
}
public function saveMessage($name, $email, $message) {
$query = "INSERT INTO " . $this->table . "
SET name = :name,
email = :email,
message = :message";
$stmt = $this->conn->prepare($query);
// Sanitize inputs
$name = htmlspecialchars(strip_tags($name));
$email = htmlspecialchars(strip_tags($email));
$message = htmlspecialchars(strip_tags($message));
// Validate email
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
return "Invalid email format";
}
// Bind parameters
$stmt->bindParam(":name", $name);
$stmt->bindParam(":email", $email);
$stmt->bindParam(":message", $message);
if($stmt->execute()) {
// Send email notification (optional)
$this->sendEmailNotification($name, $email, $message);
return "success";
}
return "Database error";
}
private function sendEmailNotification($name, $email, $message) {
$to = "info@aquilon-robotics.com";
$subject = "New Contact Form Submission from " . $name;
$headers = "From: " . $email . "\r\n";
$headers .= "Reply-To: " . $email . "\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$email_body = "
<html>
<head>
<title>New Contact Form Submission</title>
</head>
<body>
<h2>New Contact Form Submission</h2>
<p><strong>Name:</strong> " . $name . "</p>
<p><strong>Email:</strong> " . $email . "</p>
<p><strong>Message:</strong><br>" . nl2br($message) . "</p>
<p><strong>Submitted:</strong> " . date('Y-m-d H:i:s') . "</p>
</body>
</html>
";
mail($to, $subject, $email_body, $headers);
}
}
?>