-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_message.php
More file actions
29 lines (26 loc) · 1.02 KB
/
send_message.php
File metadata and controls
29 lines (26 loc) · 1.02 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
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the form data
$name = htmlspecialchars($_POST['name']);
$email = htmlspecialchars($_POST['email']);
$message = htmlspecialchars($_POST['message']);
// Validate the data (you can add more validation here)
if (!empty($name) && !empty($email) && !empty($message)) {
// Specify the file path where you want to save the messages
$file = 'messages.txt';
// Format the message to be written into the file
$message_content = "Name: $name\n";
$message_content .= "Email: $email\n";
$message_content .= "Message: $message\n";
$message_content .= "-----------------------------\n";
// Write the message to the file
if (file_put_contents($file, $message_content, FILE_APPEND | LOCK_EX)) {
echo "Thank you for your message!";
} else {
echo "Sorry, there was an error processing your message.";
}
} else {
echo "Please fill in all fields.";
}
}
?>