John Barcy
John Barcy

Reputation: 11

PHP Mailer script not receiving POST variables

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.

Upvotes: 0

Views: 125

Answers (1)

Gustaf Gun&#233;r
Gustaf Gun&#233;r

Reputation: 2267

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.

Upvotes: 1

Related Questions