My page structure is the following
-index.php
-include send-form.php
-include contact-us-form.php
-include footer.php
my index.php file is the following (shortened)
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
</head>
<body>
<?php include 'navigation-bar.php';?>
<?php include 'contact-us-form.php';?>
<?php include 'footer.php';?>
</body>
below is my contact-us-form
<div class="container">
<div class="row">
<div class="column">
<form method="post">
<label for="name">Name*</label>
<input type="text" id="name" name="name" placeholder="Your name.." required>
<label for="email">Email*</label>
<input type="text" id="email" name="email" placeholder="Your email.." required>
<label for="message">Message*</label>
<textarea id="message" name="message" placeholder="Your Message" style="height:170px" required></textarea>
<div style="text-align: center;">
<input type="submit" value="submit" >
</div> <!-- /submit button -->
</form> <!-- /form -->
<div id="error_message" style="width:100%; height:100%; display:none; ">
<h4>Error</h4>
Sorry there was an error sending your form.
</div>
<div id="success_message" style="width:100%; height:100%; display:none; ">
<h2>Success! Your Message was Sent Successfully.</h2>
</div>
</div><!-- /column -->
<div class="column2">
</div> <!-- /column2 -->
</div> <!-- /row-->
</div> <!-- /container -->
below is my send-form.php
if (isset($_POST["submit"])){
$to = '***************@gmail.com';
$subject = 'Message from website';
$message = 'MESSAGE: ' . $_POST [ "message" ] . ' </n> NAME: ' . $_POST['name'] ;
$from = $_POST[ "email" ];
if(mail($to, $subject, $message)){
echo 'message sent';
} else{
echo 'Unable to send email. Please try again.';
}
}
For some reason the email isn't sending. I can get the email to send if I put a action="/send-form.php" in the contact form but this bring me to another page.. What I am trying to do is for the user to send the form and stay on the same page where the message which is hidden will then be unhidden when clicked.. Any help on why my email isn't sending would be greatly appreciated!
I see you used $_POST["submit"] in your code. But you didn't define it on your form.
<input type="submit" value="submit">
Just put name="submit" on it and the problem must be solved.
<input type="submit" name="submit" value="submit">