I am trying to make an HTML form work.
My frontend code is this:
<form action="/form_validation.php" target="_blank">
<p><input class="w3-input w3-padding-16" type="text" placeholder="name" required name="name"></p>
<p><input class="w3-input w3-padding-16" type="text" placeholder="email" required name="email"></p>
<p><input class="w3-input w3-padding-16" type="text" placeholder="subject" required name="subject"></p>
<p><input class="w3-input w3-padding-16" type="text" placeholder="comment" required name="comment"></p>
<p>
<button class="w3-button w3-light-grey w3-padding-large" type="submit">
<i class="fa fa-paper-plane"></i> SEND MESSAGE
</button>
</p>
</form>
<p><?php echo $feedbackmsg;?></p>
and the file form_validation.php
contains this:
<?php
$nameErr = $emailErr = $commentErr = $subjectErr = "";
$name = $email = $comment = $subject = "";
$feedbackmsg = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST['submit'])) {
if (empty($_POST["name"])) {
$nameErr = "*Name is required";
} else {
$name = validate($_POST["name"]);
if (!preg_match("/^[a-zA-Z ]*$/", $name)) {
$nameErr = "*Only letters and white space allowed";
}
}
if (empty($_POST["subject"])) {
$subjectErr = "*Subject is required";
} else {
$subject = validate($_POST["subject"]);
if (!preg_match("/^[a-zA-Z ]*$/", $subject)) {
$SubjectErr = "*Only letters and white space allowed";
}
}
if (empty($_POST["email"])) {
$emailErr = "*Email is required";
} else {
$email = validate($_POST["email"]);
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) {
$emailErr = "*Invalid email format";
}
}
if (empty($_POST["comment"])) {
$commentErr = "*Write Me something";
} else {
$comment = validate($_POST["comment"]);
}
if (empty($nameErr) && empty($emailErr) && empty($commentErr)) {
$to = "myEmail@gmail.com";
$subject = $name;
mail($to, $subject, $comment, $email);
$feedbackmsg = "Your message has sent,<br> thanks";
}
}
}
So when action triggered returns back a blank page with the following url with my summury: mysite.com/form_validation.php?name=anastasios&email=myemail%40hotmail.com&subject=mysubject&comment=ena+dio+ena+dio
I think this shoyld be normal. but why I dont have any email if it works properly? Any thoughts? thanks a lot