-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
“Muhammad
committed
Oct 13, 2024
1 parent
f187819
commit 50aefbe
Showing
4 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
if ($_SERVER["REQUEST_METHOD"] == "POST") { | ||
// Collect form data | ||
$name = htmlspecialchars($_POST['name']); | ||
$email = htmlspecialchars($_POST['email']); | ||
$message = htmlspecialchars($_POST['message']); | ||
|
||
// Validate the data (simple validation) | ||
if (empty($name) || empty($email) || empty($message)) { | ||
echo "All fields are required!"; | ||
exit; | ||
} | ||
|
||
// Sanitize email and validate | ||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { | ||
echo "Invalid email format!"; | ||
exit; | ||
} | ||
|
||
// Prepare the email | ||
$to = "[email protected]"; // Your email address to receive the form data | ||
$subject = "New message from $name"; | ||
$body = "Name: $name\n"; | ||
$body .= "Email: $email\n\n"; | ||
$body .= "Message:\n$message\n"; | ||
|
||
$headers = "From: $email"; | ||
|
||
// Send the email | ||
if (mail($to, $subject, $body, $headers)) { | ||
echo "Message sent successfully!"; | ||
} else { | ||
echo "Failed to send the message!"; | ||
} | ||
} else { | ||
echo "Invalid request!"; | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters