12 Replies Latest reply: Dec 3, 2014 6:09 AM by trenholme90 RSS

    My php contact form won't work. HELP!?

    trenholme90 Community Member

      I've been trying this for a while now, following a few different online tutorials. It seems like a simple concept but i just cannot get the contact form to relay any data. I'll paste my php coding and my form below. Any help would be much appreciated. Thanks.

       

      <div class="contact_form">

          <form id="contactform" action="contact.php" method="post">

        Name: <br><input name="name" type="text" id="name" value=""/>

          <br><br>

          Company Name: <br><input name="company_name" type="text" id="company_name" value=""/>

          <br><br>

          Telephone: <br><input name="telephone" type="tel" id="telephone" value=""/>

          <br><br>

          Email: <br><input name="email" type="email" id="email" value=""/>

          <br><br>

          Comments: <br><textarea name="comments" id="comments" value="" />  

          </textarea>

          <p></p>

          <input type="submit" name="submit" value="Send!"/>

         

      </form> 

      </div>

       

       

       

       

       

      <?php

       

      if (isset($_POST['name']) && isset ($_POST['company_name']) && isset ($_POST['telephone']) && isset ($_POST['email']) && isset ($_POST['coments']) ) {

        $name = $_POST['name'];

        $company_name = $_POST['company_name'];

        $telephone = $_POST['telephone'];

        $email = $_POST['email'];

        $comments = $_POST['comments'];

       

        if (!empty($name) && !empty($company_name) && !empty($telephone) && !empty($email) && !empty($comments) ) {

       

        $to = 'trenholme90@hotmail.com';

        $subject = 'Contact form submitted.';

        $body = $name. "\n" .$comments;

        $headers = 'From: ' .$email;

       

        if (@mail($to, $subject, $body, $headers)) {

        echo 'Thanks for contacting us. We\'ll be in touch soon!';

        } else {

        echo 'Sorry an error occurred. Please try again later.';

       

        }

       

        } else {

        echo 'All fields are required.';

        }

       

        }

       

      ?>