Variables are not receiving input value in PHP

Asked

Viewed 45 times

2

I have this form to send messages to the email:

 <form action="contato.php" name="sentMessage" id="contactForm" novalidate>
                    <div class="row">
                        <div class="col-md-6 wow fadeInLeft" data-wow-duration="2s" data-wow-delay="600ms">
                            <div class="form-group">
                                <input type="text" name="name" class="form-control" placeholder="Nome *" id="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" name="email" class="form-control" placeholder="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" name="phone" class="form-control" placeholder="Telefone *" id="phone" required data-validation-required-message="Please enter your phone number.">
                                <p class="help-block text-danger"></p>
                            </div>
                        </div>
                        <div class="col-md-6 wow fadeInRight" data-wow-duration="2s" data-wow-delay="600ms">
                            <div class="form-group">
                                <textarea class="form-control" name="message" placeholder="Mensagem *" 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 wow zoomIn" data-wow-duration="1s" data-wow-delay="600ms">
                            <div id="success"></div>
                            <button type="submit" class="btn btn-primary">Enviar</button>
                        </div>
                    </div>
                </form>

To action of the form sends to the same page, and at the top of the page I put the following code:

<?php

   $nome = $_POST['name'];
   $email = $_POST['email'];
   $telefone = $_POST['phone'];
   $mensagem = $_POST['message'];

   $to = "[email protected]";

   $subject = "Email do Site";

   $headers = "De:";

   $corpo  = "Nome: ".$nome."<BR>\n";
   $corpo .= "Email: ".$email."<BR>\n";
   $corpo .= "Telefone: ".$telefone."<BR>\n";
   $corpo .= "Mensagem: ".$mensagem."<BR>\n";

   Mail($to, $subject, $corpo, $headers);

   ?>

It is sending email normally, but the body of the email is not getting the values of the variables.

  • I didn’t understand why you accepted mine that was answered first and then changed.

2 answers

4


Missing attribute method=POST, change to this:

 <form method="POST" action="contato.php" name="sentMessage" id="contactForm" novalidate>

1

Try to put the method="POST" in the form tag:

<form action="contato.php" name="sentMessage" id="contactForm" method="POST" novalidate>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.