skip to Main Content

Forgive me, as this probably has an extremely simple solution and I’m just very inexperienced.

I am using the Massive HTML5 theme and cannot get my contact form to work. I thought I followed the directions, but still nothing happens when I click SUBMIT.

<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<form method="post" action="contact-us.php" id="form" role="form" class="contact-comments">
  <div class="row">
    <div class="col-md-6 ">
      <div class="form-group">
        <!-- Name -->
        <input type="text" name="name" id="name" class=" form-control" placeholder="Name *" maxlength="100" required="">
      </div>
      <div class="form-group">
        <!-- Email -->
        <input type="email" name="email" id="email" class=" form-control" placeholder="Email *" maxlength="100" required="">
      </div>
      <div class="form-group">
        <!-- phone -->
        <input type="text" name="phone" id="phone" class=" form-control" placeholder="Phone" maxlength="100">
      </div>
    </div>
    <div class="col-md-6 form-group">
      <div class="form-group">
        <!-- Comment -->
        <textarea name="text" id="text" class="cmnt-text form-control" placeholder="Comment" maxlength="400"></textarea>
      </div>
      <div class="form-group full-width">
        <button type="submit" class="btn btn-small btn-dark-solid ">
          Send Message
        </button>
      </div>
    </div>
  </div>
</form>
<?php
// Note: filter_var() requires PHP >= 5.2.0
if ( isset($_POST['name']) && isset($_POST['email']) && isset($_POST['subject']) && isset($_POST['comments']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {

    // detect & prevent header injections
    $mailTest = "/(content-type|bcc:|cc:|to:)/i";
    foreach ( $_POST as $key => $val ) {
        if ( preg_match( $mailTest, $val ) ) {
            exit;
        }
    }

    $headers = 'From: ' . $_POST["name"] . '<' . $_POST["email"] . '>' . "rn" .
    'Reply-To: ' . $_POST["email"] . "rn" .
    'X-Mailer: PHP/' . phpversion();

    $success = mail( "[email protected]", $_POST['subject'], $_POST['comments'], $headers );
    //  Replace with your email

    if ($success) {
        ?>
        <div style="color:#3c763d;padding:30px;text-align:center">
            <strong>Success!</strong> Message has been sent successfully.
        </div>
        <?php
    }
}

Of course, I changed [email protected] to my address.

Thanks for the help.

3

Answers


  1. mail() function Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

    It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.

    please refer Documentation .

    you can also other php library to send mail like phpmailer.

    Login or Signup to reply.
  2.  if ( isset($_POST['name']) && isset($_POST['email']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) 
    

    Remove && isset($_POST[‘subject’]) && isset($_POST[‘comments’]) from your if condition as their are no inputs with names subject and comments in your HTML form.

    Login or Signup to reply.
  3. If you’re on Windows then use XAMPP, if on Mac use MAMP.

    PHP contact form will not work if don’t have any server side connection. I had the similar problem as you have now. For more information please check my post Configuration issue with PHP contact form.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search