Hello, gentlemen. Need your help. There is a feedback form and php script file for it.
HTML:
<form class="form-horizontal" id="feedback" role="form" method="post" action="sendemail.php"> <div class="form-group"> <label for="name" class="col-sm-2 control-label">Имя</label> <div class="col-sm-10"> <input type="text" class="form-control" id="name" name="name" placeholder="First & Last Name" > </div> </div> <div class="form-group"> <label for="email" class="col-sm-2 control-label">Ваш Email</label> <div class="col-sm-10"> <input type="email" class="form-control" id="email" name="email" placeholder="example@domain.com" > </div> </div> <div class="form-group"> <label for="message" class="col-sm-2 control-label">Сообщение</label> <div class="col-sm-10"> <textarea class="form-control" rows="4" name="message"></textarea> </div> </div> <div class="form-group"> <label for="human" class="col-sm-2 control-label">2 + 3 = ?</label> <div class="col-sm-10"> <input type="text" class="form-control" id="human" name="human" placeholder="Your Answer"> </div> </div> <div class="form-group"> <div class="col-sm-10 col-sm-offset-2"> <input id="submit" name="submit" type="submit" value="Отправить" class="btn btn-primary"> </div> </div> <div class="form-group"> <div class="col-sm-10 col-sm-offset-2"> <?php echo $result; ?> </div> </div> </form> PHP:
<?php if (isset($_POST["submit"])) { $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $human = intval($_POST['human']); $from = 'Demo Contact Form'; $to = 'piskunovalxy@gmail.com'; $subject = 'Message from Contact Demo '; $body = "From: $name\n E-Mail: $email\n Message:\n $message"; // Check if name has been entered if (!$_POST['name']) { $errName = 'Please enter your name'; } // Check if email has been entered and is valid if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { $errEmail = 'Please enter a valid email address'; } //Check if message has been entered if (!$_POST['message']) { $errMessage = 'Please enter your message'; } //Check if simple anti-bot test is correct if ($human !== 5) { $errHuman = 'Your anti-spam is incorrect'; } if (!$errName && !$errEmail && !$errMessage && !$errHuman) { if (mail ($to, $subject, $body, $from)) { $result='<div class="alert alert-success">Thank You! I will be in touch</div>'; header ('Location: index.html'); } else { $result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>'; } } } ?> The problem is that messages come, if all fields are filled, including anti-spam. But if one of the fields is empty or anti-spam is not correct, then the white page of the script is knocked out. Thank you in advance
if (!$errName && !$errEmail && !$errMessage && !$errHuman)? - vp_arth$resultvariable remains undefined. - vp_arth