1

I'm trying to create a html and php contact form but it doesn't seem to be working. I'm sure it's a simple answer but I can't figure it out.

Can anyone tell me were i'm going wrong? It doesn't redirect to the mail.php page.

        <div class="col-lg-8">
        <form action="mail.php" class="form-horizontal"  id="contactForm" name="contactForm"  method="post" >
            <div class="form-group" >


            <label for="first-name"  class="col-lg-2">First name</label>
            <div class="col-lg-10">
            <input type="text" class="form-control" id="first-name" name="first-name" placeholder="What your mam calls you ">
            </div>
    </div><!--end form group-->

    <div class="form-group">
            <label for="last-name"   class="col-lg-2">Last name</label>
            <div class="col-lg-10">
            <input type="text" class="form-control" id="last-name" name="last-name" placeholder="What your army buddies call you">
    </div>
    </div><!--end form group-->
    <div class="form-group">
            <label for="email" class="col-lg-2">Email</label>
            <div class="col-lg-10">
            <input type="text" class="form-control" id="email" name="email" placeholder="Enter your email address, we won't send you junk mail">
            </div>
    </div><!--end form group-->
    <div class="form-group">
            <label for="website" class="col-lg-2">Your current website</label>
            <div class="col-lg-10">
            <input type="text" class="form-control" id="website" name="website" placeholder="If you have one.">
    </div>
    </div><!--end form group-->
    <div class="form-group">
            <label for="message" class="col-lg-2">Any Message</label>
            <div class="col-lg-10">
            <textarea name="message" id="message" name="message" class="form-control"
            cols="20" rows="10" placeholder="Maybe tells us a bit about your business.  I'll start, mine is web development. ;)"></textarea>
            </div>
    </div><!--end form group-->

        <div class="form-group">
            <div class="col-lg-10 col-lg-offset-2">
            <button type="submit" class="btn btn-primary">Submit</button>
            </div>
        </div>
        </form>
    </div>
    </div><!--end of row-->
</section>
</div>

mail.php

    <html>

<body>

<?php 
if(isset($_POST['submit'])){
    $to = "info@wonderfulwebsites.ie"; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    $f_name = $_POST['first_name'];
    $s_name = $_POST['last_name'];
    $subject = "Form submission";
    $subject2 = "Copy of your form submission";
    $message = $f_name . " " . $s_name . " wrote the following:" . "\n\n" . $_POST['message'] "\n" $website = $_POST['website'];
    $message2 = "Here is a copy of your message " . $f_name . "\n\n" . $_POST['message'];

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
    echo "Mail Sent. Thank you " . $f_name . ", we will contact you shortly.";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
    // You cannot use header and echo together. It's one or the other.
    }
?>

    </body>
    </html> 
Derek Joseph
  • 59
  • 1
  • 5

1 Answers1

1

Change this:

<button type="submit" class="btn btn-primary">Submit</button>

to this:

<input type="submit" class="btn btn-primary" value="Submit" />
Ahs N
  • 8,233
  • 1
  • 28
  • 33