Below is the php code i have on my website. We get some form submissions that have content in them, but we have also been getting a large amount of empty submissions. When i try to submit a form without filling it. out the site wont allow it. BUT lately a. lot have been coming in looking like this.
“Information Submitted:
Name:
Email:
Phone:
Message:
”
Is this someone trying to hack my site?
I am very new to coding/backend web development and have basically taught myself everything through youtube so i definitely need some help.
<?php
$userName = $_POST['name-3'];
$userPhone = $_POST['name-2'];
$userEmail = htmlspecialchars($_POST['email-2']);
$userMessage = $_POST['email-3'];
$to = "[email protected]";
$subject = "Email from my website";
$body = "Information Submitted:";
$body .= "rn Name: " . $userName;
$body .= "rn Email: " . $userEmail;
$body .= "rn Phone: " . $userPhone;
$body .= "rn Message: " . $userMessage;
mail($to, $subject, $body);///
if (filter_var($userEmail, FILTER_VALIDATE_EMAIL)){
//email is valid
} else {
//email is invalid
}
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
$success = "Message successfully sent";
} else {
$success = "Message Sending Failed, try again";
}
}
?>
My site is hosted on Cpannel through Godaddy. In my web files, there is an error log that tells me “Undefined array key “submit” in /send.php” for each line of the fields below. I feel like this is going to be a super simple fix and I would appreciate the help!
I have tried adding different validations and such but in general I am just confused.
ilana a is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.