0

I created the form in my HTML file below and also the PHP file below that. However I cannot seem to get it to send to email address listed as "$to".

I keep getting the message "Email not sent" which is what is supposed to return when the email doesn't send...but I don't know why.

<form method="POST" action="mailer.php" id="formid">
 <div class="row">
    <div class="col-md-6">
        <div class="form-group">
            <input type="text" class="form-control" name="name" placeholder="Your Name" required="">
        </div>
    </div>

    <div class="col-md-6">
        <div class="form-group">
            <input type="email" class="form-control" name="email" placeholder="Email" required="">
        </div>
    </div>
 </div>



  <div class="form-group">
    <textarea class="form-control" name="message" rows="8" placeholder="Message"></textarea>
  </div>

  <div class="center-content">
    <input type="submit" value="SEND" class="btn btn-lg">
  </div>

<?php
if(isset($_POST['submit'])) 
{
    $to = "myemail@email.com";
    $subject = "Customer Enquiry";
    $name_field = $_POST['name'];
    $email_field = $_POST['email'];
    $message = $_POST['message'];

    $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

    echo "Thanks for your enquiry! Expect a response within 24 hours.";
    mail($to, $subject, $body);
} 
else 
{
    echo "Email not sent";
}
?>
TheBear
  • 23
  • 1
  • 5
  • `if(isset($_POST['submit'])){...}` never happened. – Funk Forty Niner Jan 05 '18 at 03:42
  • I know how an IF statement works. Just don't understand why this one isn't. I'm sure it's something really obvious that I'm missing. – TheBear Jan 05 '18 at 03:53
  • name your submit button. you should have gotten an undefined index notice, but you didn't have your system's error reporting set to catch and display. Everything can be found in the duplicate that the question was closed with. – Funk Forty Niner Jan 05 '18 at 03:55

0 Answers0