0

when a contact me script is run on my website, the script doesn't seem to be grabbing the POST variables from the HTML. The HTML is as follows:

<section id="contact">
    <div class="container">
        <div class="row">
            <div class="col-lg-12 text-center">
                <h2 class="section-heading">Contact Us</h2>
                <h3 class="section-subheading text-muted">Fill out a form below to make an appointment, and our top masseur will be with you as soon as possible!</h3>
            </div>
        </div>
        <!--  To Do: Change pictures, add FA's, finish "about",and remove portfolio-->
        <div class="row">
            <div class="col-lg-12">
                <form name="sentMessage" id="contactForm" formaction="mail/contact_me.php" method="POST" novalidate>
                    <div class="row">
                        <div id="center><div class="col-md-6">
                            <center><div class="form-group">
                                <input type="text" class="form-control" placeholder="Your Name *" id="name" name="name" required data-validation-required-message="Please enter your name.">
                                <p class="help-block text-danger"></p>
                            </div>
                            <div class="form-group">
                                <input type="email" class="form-control" placeholder="Your Email *" id="email" required data-validation-required-message="Please enter your email address.">
                                <p class="help-block text-danger"></p>
                            </div>
                            <div class="form-group">
                                <input type="tel" class="form-control" placeholder="Your Phone *" id="phone" required data-validation-required-message="Please enter your phone number.">
                                <p class="help-block text-danger"></p>
                            </div>
                            <div class="form-group">
                                <input type="tel" class="form-control" placeholder="Massage Type *" id="type" required data-validation-required-message="Please enter your type of massage.">
                                <p class="help-block text-danger"></p>
                            </div>
                            <div class="form-group">
                                <input type="tel" class="form-control" placeholder="Date of desired appointment *" id="message" required data-validation-required-message="Please enter the date">
                                <p class="help-block text-danger"></p>
                            </div>
                        </div>
                        <!--<div class="col-md-6">

                            <div class="form-group">
                                <textarea class="form-control" placeholder="Please include date, and type of massage *" id="message" required data-validation-required-message="Please enter a message."></textarea>
                                <p class="help-block text-danger"></p>
                            </div>
                        </div> -->
                        <div class="clearfix"></div>
                        <div class="col-lg-12 text-center">
                            <button type="submit" class="btn btn-xl" formaction="mail/contact_me.php">Set Appointment!</button> 
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>

The PHP Script (contact_me.php) is:

<?php 
if(isset($_POST['submit'])){
$to = "*****"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['name'];
$subject = "New Appointment!";
$subject2 = "Copy of your Appointment credentials.";
$message = $first_name . "'s Appointment. Phone: " . $phone . " Email: " . $_POST['email'] . " Type of Massage:" . "\n\n" . $_POST['type'] . " On:" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_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 " . $first_name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>

I tried removing the isset (Or rather changing it to !isset), and the email sent. However, the credentials and the fields that were provided at the website were completely missing, and only the given text in the script was sent.

4
  • 1
    you are missing name attribute for your form field except first one. check that, specify them and then try and tell what happen? Commented Jul 2, 2015 at 20:09
  • formaction=...? that's not valid in <form> tags. Commented Jul 2, 2015 at 20:17
  • 1
    isset($_POST['submit']) will return false because there's no form variable with the name "submit". Try adding print_r($_POST); at the start of your PHP file to see what variables are being passed through. Commented Jul 2, 2015 at 21:03
  • The biggest issue here is that you've not tried very hard to diagnose the problem. Giving the solution is simple enough, but you might want to spend some time thinking about how you could diagnose the problem - simplifying the form and php script, adding instrumentation to your code, looking at what's coming out of the browser using tamperdata msieheaders, liveheaders or similar. Commented Jul 2, 2015 at 22:14

1 Answer 1

1

The attribute formaction is not valid. Use action instead.

In your case:

<form name="sentMessage" id="contactForm" action="mail/contact_me.php" method="POST" novalidate>

You're also missing a name attribute, as @anant kumar singh stated.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.