Problems with sending a question form with the assembly of PHP


I am having problems with setting up a PHP for a form on a website, the problem is that I do not receive the data that I am putting into each input. I wanted to know if it is well armed or if I have to take into account something to be able to perform this test. On the other hand, may it be possible that I have to configure something in my email account to get them to me? Because I test with several accounts and nothing happens.

$remitente = $_POST['email'];
$destinatario = '[email protected]'; // en esta línea va el mail del destinatario, puede ser una cuenta de hotmail, yahoo, gmail, etc
$asunto = 'Consulta Bricsa'; // acá se puede modificar el asunto del mail
if (!$_POST){

    $cuerpo = "Nombre: " . $_POST["nombre"] . "\r \n"; 
    $cuerpo .= "Empresa: " . $_POST["empresa"] . "\r \n";
    $cuerpo .= "Email: " . $_POST["email"] . "\r \n";
    $cuerpo .= "Telefono: " . $_POST["telefono"] . "\r \n";
    $cuerpo .= "Consulta: " . $_POST["consulta"] . "\r\n";

    $headers  = "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/plain; charset=utf-8\n";
    $headers .= "X-Priority: 3\n";
    $headers .= "X-MSMail-Priority: Normal\n";
    $headers .= "X-Mailer: php\n";
    $headers .= "From: \"".$_POST['nombre']." ".$_POST['empresa']."\" <".$remitente.">\n";

    mail($destinatario, $asunto, $cuerpo, $headers);
    include 'confirmacion.html'; //se debe crear un html que confirma el envío
<form role="form" action="contacto.php" method="post">

  <input maxlength="100" required="required" class="form-control" placeholder="Nombre y Apellido" type="text" name="nombre" />

  <input maxlength="100" type="text" required="required" class="form-control" placeholder="Empresa" type="text" name="empresa" />

  <input maxlength="100" required="required" class="form-control" type="email" name="email" placeholder="Email" id="contact-email" />

  <input maxlength="100" type="text" required="required" class="form-control" placeholder="Teléfono" name="telefono" />

  <textarea class="form-control" name="consulta" maxlength="1200" rows="4" placeholder="Dejanos tu consulta..."></textarea>

  <input class="btn" type="submit" name="" value="ENVIAR">
asked by Mariano Andres Franco 29.11.2018 в 16:20

1 answer


Maybe I'm asking the obvious but: is the file contacto.php the one with the php code to send the mail? (The form sends the data to that file).

Additionally, the way I do the validation is to put a name (name) on the "SEND" button and then check if that variable exists (that is, if you have clicked on that button):

if(isset($_POST['enviar']) {
    // Tu codigo aqui

It's also good if you do not use the $ _POST [] variables directly, but filter them using filter_input ():

$email = filter_input(INPUT_POST, 'email');    // En lugar de $_POST['email']
answered by 29.11.2018 в 17:48