Skip to content

Commit

Permalink
Update contact-from.php
Browse files Browse the repository at this point in the history
#
  • Loading branch information
Harsh-tantia authored Apr 22, 2024
1 parent 4a57911 commit fa8ba34
Showing 1 changed file with 5 additions and 31 deletions.
36 changes: 5 additions & 31 deletions php/contact-from.php
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Function to sanitize and validate email
function sanitize_email($email) {
// Remove all illegal characters from email
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate email
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
return $email;
} else {
return false;
}
}

// Function to filter out bad words
function filter_bad_words($input) {
// List of bad words to filter out
$bad_words = array("badword1", "badword2", "badword3");
// Replace bad words with asterisks
return str_ireplace($bad_words, "***", $input);
}

// Get the form data and sanitize/validate inputs
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$email = sanitize_email($_POST['email']);
$subject = filter_bad_words($_POST['subject']);
$message = filter_bad_words($_POST['message']);

// Check if email is valid
if ($email === false) {
echo json_encode(array("success" => false, "message" => "Invalid email address."));
exit;
}
// Get the form data
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];

// Email address to receive the message
$to = 'hv71673@gmail.com'; // Replace with your email address
Expand Down

0 comments on commit fa8ba34

Please sign in to comment.