PHP email script keeps rejecting entry even though checks are passed - php

I have written a PHP script for a contact form however it is not working, as when I press submit the message "Error with sending the message" pops up instead of the confirmation message (see at the end of the php code). I am at a loss here. The script and html are stored in a single file called "contact.php"
The php script is as follows
<?php
if($_POST["submit"]){
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$human = intval($_POST['human']);
$to = 'faisalhussien#hotmail.com';
$message = "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';
}
if (!$_POST['subject']){
$errSubject = 'Please include the subject of the message';
}
//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 answer is incorrect';
}
if(!$errName && !$errEmail && !$errSubject && !$errMessage && !$errHuman){
if (mail ($to, $subject, $message)) {
$result='<div class="alert alert-success">Thank You! I will be in touch</div>';
} else {
$result='<div class="alert alert-danger">Error with sending the message</div>';
}
}
}
?>
And my HTML for the form is:
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h1 class="page-header text-center">Contact</h1>
<form class="form-horizontal" role="form" method="post" action="contact.php">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name" placeholder="First & Last Name" value="<?php echo htmlspecialchars($_POST['name']); ?>">
<?php echo "<p class='text-danger'>$errName</p>";?>
</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" value="<?php echo htmlspecialchars($_POST['email']); ?>">
<?php echo "<p class='text-danger'>$errEmail</p>";?>
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Subject</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="subject" name="subject" placeholder="Subject" value="<?php echo htmlspecialchars($_POST['subject']); ?>">
<?php echo "<p class='text-danger'>$errSubject</p>";?>
</div>
</div>
<div class="form-group">
<label for="message" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="message"><?php echo htmlspecialchars($_POST['message']);?></textarea>
<?php echo "<p class='text-danger'>$errMessage</p>";?>
</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">
<?php echo "<p class='text-danger'>$errHuman</p>";?>
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<input id="submit" name="submit" type="submit" value="Send" 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>
</div>
</div>
</div>
To test the code I am using MAMP on windows (in case that is where the fault lays)

Related

Bootstrap Contact Form Processing

Have a Bootstrap contact form coded and working with on exception. When the form is submitted it doesn't tell the user the message was sent. I want when the user sends the data it gets process on the same page with a successful message. Can anyone tell me what I am doing wrong or give me a fix?
<form class="form-horizontal" role="form" method="post" action="">
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$human = intval($_POST['human']);
$from = '3Form';
$to = 'info#gmail.com';
$subject = 'Message from 360 Form ';
$body = "From: $name\n E-Mail: $email\n Phone: $phone\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 Phone
if (!$_POST['phone']) {
$errPhone = 'Please enter a phone Number';
}
//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 there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage && !$errHuman) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You! we will be in touch</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
}
}
?>
<div class="form-group">
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name" placeholder="First & Last Name" value="">
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="example#domain.com" value="">
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<input type="tel" class="form-control" id="phone" name="phone" placeholder="Phone" value="">
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="message" placeholder="Message"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<input type="text" class="form-control" id="human" name="human" placeholder="2 + 3 = ?">
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<! Will be used to display an alert to the user>
</div>
</div>
</form>
i made a few changes in your code you have to use the isset function in php, and for the error message you should create it in your CSS file, last thing i removed the authentication because i prefer to write a js/jquery .
<body>
<?php if (!isset($_POST['name'])) { ?>
<form class="form-horizontal" role="form" method="post" action="">
<div class="form-group">
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name" placeholder="First & Last Name" value="">
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="example#domain.com" value="">
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<input type="tel" class="form-control" id="phone" name="phone" placeholder="Phone" value="">
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="message" placeholder="Message"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<input type="text" class="form-control" id="human" name="human" placeholder="2 + 3 = ?">
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">
</div>
</div>
</div>
<?php }
else {
//connect to the db
include 'dbconnect.php';
//collect the name data
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$human = intval($_POST['human']);
$from = '360 Web Fform';
$to = 'info#360websolution.com';
$subject = 'Message from 360 Form ';
//inserting data to the DB
$sql = "INSERT INTO YourTable SET
YourTable fields....
mysqli_query($conn,$sql);
echo "<span class="error"> Your request will be processed shortly</span>";
} ?>
</body>
<form class="form-horizontal" role="form" method="post" action="">
<?php
$result ='';
$errName='';
$errEmail='';
$errPhone='';
$errMessage='';
$errHuman='';
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$human = intval($_POST['human']);
$from = '3Form';
$to = 'info#gmail.com';
$subject = 'Message from 360 Form ';
$body = "From: $name\n E-Mail: $email\n Phone: $phone\n Message:\n $message";
// Check if name has been entered
if (empty($_POST['name'])) {
$errName = 'Please enter your name';
}
// Check if email has been entered and is valid
if (empty($_POST['email']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Please enter a valid email address';
}
//Check Phone
if (empty($_POST['phone'])) {
$errPhone = 'Please enter a phone Number';
}
//Check if message has been entered
if (empty($_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 there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage && !$errHuman) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You! we will be in touch</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
}
}
?>
<div class="form-group">
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name" placeholder="First & Last Name" value="">
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="example#domain.com" value="">
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<input type="tel" class="form-control" id="phone" name="phone" placeholder="Phone" value="">
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="message" placeholder="Message"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<input type="text" class="form-control" id="human" name="human" placeholder="2 + 3 = ?">
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<?=$result;?>
</div>
</div>
</form>
to mailing u need to read here
Send email from localhost running XAMMP in PHP using GMAIL mail server

Bootstrap v4 form red error border

I'm just experimenting with the contact form of Bootstrap v4 and some PHP validation, but struggling to the red error border.
When the email input is not correct, a red border comes around with a text-balloon and with a red error message underneath it. That's just what I want. But this doesn't happen at the Name input. I just don't see where it goes wrong. I checked all the classes, but they're all identical.
Can someone help?
I know only name and email have !preg_match so far.
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$human = intval($_POST['human']);
$from = 'Demo Contact Form';
$to = 'example#bootstrapbay.com';
$subject = 'Message from Contact Demo ';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
// Check if name has been entered
if (!preg_match("/^[a-zA-Z]+[a-zA-Z[:space:]]{2,}$/", $_POST['name'])) {
$errName = 'Please enter your name';
}
// Check if email has been entered and is valid
if (!preg_match("/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*#([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)*\.([a-zA-Z]{2,6})$/", $_POST['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 there are no errors, send the email
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>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
}
}
?>
<form class="form-horizontal" role="form" method="post" action="contact_test.php">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name" placeholder="First & Last Name" value="<?php echo htmlspecialchars($_POST['name']); ?>">
<?php echo "<p class='text-danger'>$errName</p>";?>
</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" value="<?php echo htmlspecialchars($_POST['email']); ?>">
<?php echo "<p class='text-danger'>$errEmail</p>";?>
</div>
</div>
<div class="form-group">
<label for="message" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="message"><?php echo htmlspecialchars($_POST['message']);?></textarea>
<?php echo "<p class='text-danger'>$errMessage</p>";?>
</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">
<?php echo "<p class='text-danger'>$errHuman</p>";?>
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<input id="submit" name="submit" type="submit" value="Send" 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 open a modal dialog when sending a form

I got a problem with my modal dialog when i send my form. i would like to keep the modal dialog when i press the send button and display submitting succeessfully, but it doesn't do it.
This is my form code
<div class="modal fade" id="contact" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<form class="form-horizontal" role="form" method="post" action="index.php?page=contact">
<div class="modal-header">
<h4>Contact</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name" placeholder="First & Last Name" value="<?php echo htmlspecialchars($_POST['name']); ?>">
<?php echo "<p class='text-danger'>$errName</p>";?>
</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" value="<?php echo htmlspecialchars($_POST['email']); ?>">
<?php echo "<p class='text-danger'>$errEmail</p>";?>
</div>
</div>
<div class="form-group">
<label for="message" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="message"><?php echo htmlspecialchars($_POST['message']);?></textarea>
<?php echo "<p class='text-danger'>$errMessage</p>";?>
</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">
<?php echo "<p class='text-danger'>$errHuman</p>";?>
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<?php echo $result; ?>
</div>
</div>
</div>
<div class="modal-footer">
<a class="btn btn-default" data-dismiss="modal">Close</a>
<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">
</div>
</form>
</div>
</div>
When this is my php code
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$human = intval($_POST['human']);
$from = 'your email';
$to = 'example#domain.com';
$subject = 'your subject';
$body = "From: $name\nE-Mail: $email\nMessage:\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 there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage && !$errHuman) {
if (mail ($to, $subject, $body, $from, $email)) {
$result='<div class="alert alert-success">Thank You! I will be in touch</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
}
}
?>
if you want to reopen your modal after you submit your form ( if you are not using Ajax ), try using this on your modal page:
$(document).ready(function() {
<?php if (isset($_POST["submit"])): ?>
$('#contact').modal('show');
<?php endif; ?>
});

how to make php contact page work

Hello I'm in need of someone how can help me with php, my current php code just takes me to a "Page not found" page so if someonw can tell me how to fix that I would be so happy.
here is the Html:
<div>
<div>
<p class="text-center" style="font-family:Aparajita; font-size:1.5vw; padding:2%;">Drop me a line</p>
</div>
<form class="form-horizontal bu_contact col-lg-4" role="form" method="post" action="index.php">
<div class="form-group">
<label for="name" class="col-sm-2 control-label glyphicon glyphicon-user"></label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name" placeholder="First & Last Name" value="">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label glyphicon glyphicon-envelope"></label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="example#domain.com" value="">
</div>
</div>
<div class="form-group">
<label for="message" class="col-sm-2 control-label glyphicon glyphicon-pencil"></label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="message" placeholder="Your Message"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
</div>
</div>
</form>
</div>
The php code:
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$human = intval($_POST['human']);
$from = 'Demo Contact Form';
$to = 'lars81wolf#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';
}
// If there are no errors, send the email
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>
';
} else {
$result='
<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later.</div>
';
}
}
}
?>
I would put it in one file name it the same as the target basically and all would be fine.
<?php
// NAME THIS FILE contact.php so that the post will send it to this file
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$human = intval($_POST['human']);
$from = 'Demo Contact Form';
$to = 'lars81wolf#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';
}
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage && !$errHuman) {
if (mail ($to, $subject, $body, $from)) {
echo '
<div class="alert alert-success">Thank You! I will be in touch</div>
';
} else {
echo '
<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later.</div>
';
}
}
} else {
// Put all your stuff that will be the normal page in here
?>
<div>
<div>
<p class="text-center" style="font-family:Aparajita; font-size:1.5vw; padding:2%;">Drop me a line</p>
</div>
<form class="form-horizontal bu_contact col-lg-4" role="form" method="post" action="contact.php">
<div class="form-group">
<label for="name" class="col-sm-2 control-label glyphicon glyphicon-user"></label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name" placeholder="First & Last Name" value="">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label glyphicon glyphicon-envelope"></label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="example#domain.com" value="">
</div>
</div>
<div class="form-group">
<label for="message" class="col-sm-2 control-label glyphicon glyphicon-pencil"></label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="message" placeholder="Your Message"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
</div>
</div>
</form>
</div>
<?php
}
?>
But do not forget all the HTML conform head and foot.
PS: I did not check for any further problems just for the routine itself. Not sure if this will really mail anything unless you configured php correctly for the use of an MTA through mail function ;)

php contact form alert is not showing

After submitting the contact form it should display "Thank You" but it doesn't display it. And when we don't type the input type the error doesn't show. My website is alzirabarretto.com/webdesigner
<!-- PHP CONTACT FORM -->
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'Portfolio Contact Form';
$to = 'alzirabarretto#gmail.com';
$subject = 'My Feedback ';
$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';
}
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage ) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You! I will be in touch</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
}
}
?>
<form class="form-horizontal" role="form" method="post" action="index.php">
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Name</label>
<input type="text" class="form-control" placeholder="Name" id="name" value="<?php echo htmlspecialchars($_POST['name']); ?>">
<?php echo "<p class='text-danger'>$errName</p>";?>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Email Address</label>
<input type="email" class="form-control" placeholder="Email" id="email" value="<?php echo htmlspecialchars($_POST['email']); ?>">
<?php echo "<p class='text-danger'>$errName</p>";?>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Subject</label>
<input type="subject" class="form-control" placeholder="Subject" id="sub">
<?php echo "<p class='text-danger'>$errName</p>";?>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label>Message</label>
<textarea rows="5" class="form-control" placeholder="Message" id="message"><?php echo htmlspecialchars($_POST['message']);?></textarea>
<?php echo "<p class='text-danger'>$errName</p>";?>
</div>
</div>
<br>
<div id="success"></div>
<div class="row">
<div class="form-group col-xs-12">
<button type="submit" class="btn btn-success btn-lg" id="submit">Send</button>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<?php echo $result; ?>
</div>
</div>
</div>
</form>
$result is out of scope when it is printed. Try defining it in start.
$result="";
Add the following code where you want to print it.
if($result!="")
{
echo $result;
}

Categories