how to link the php to the html, so that the contact form works?

1

A big hello.

I have this form with Bootstrap, however there is something that I am not sure about and it is like linking the .php, to the html so that it works when you are going to send an email that leaves the message, we received your request. Link it in the form as well, and in the head of the html, or I do not know if it can be displayed so it must be mounted on the server.

Thanks.

<?php
if(isset($_POST['email'])) {
 
    // 
 
    $email_to = "[email protected]";
 
    $email_subject = "Contacto desde Web";
 
    function died($error) {
 
        // mensajes de error
 
        echo "Lo sentimos, hubo un error en sus datos y el formulario no puede ser enviado en este momento. ";
 
        echo "Detalle de los errores.<br /><br />";
 
        echo $error."<br /><br />";
 
        echo "Porfavor corrija estos errores e inténtelo de nuevo.<br /><br />";
        die();
    }
 
    // Se valida que los campos del formulairo estén llenos
 
    if(!isset($_POST['nombre']) ||
 
        !isset($_POST['telefono']) ||
 
        !isset($_POST['email']) ||
 
        !isset($_POST['solicitud']) ||
 
        !isset($_POST['message'])) {
 
        die('Lo sentimos pero parece haber un problema con los datos enviados.');
 
    }
 //En esta parte el valor "name"  sirve para crear las variables que recolectaran la información de cada campo
 
    $nombre = $_POST['nombre']; // requerido
 
    $telefono = $_POST['telefono']; // requerido
 
    $email_from = $_POST['email']; // requerido
 
    $solicitud = $_POST['solicitud']; // no requerido 
 
    $message = $_POST['message']; // requerido
 
    $error_message = "";//Linea numero 52;
 
//En esta parte se verifica que la dirección de correo sea válida 
 
   $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
 
  if(!preg_match($email_exp,$email_from)) {
 
    $error_message .= 'La dirección de correo proporcionada no es válida.<br />';
 
  }
 
//En esta parte se validan las cadenas de texto
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$first_name)) {
 
    $error_message .= 'El formato del nombre no es válido<br />';
 
  }
 
  if(!preg_match($string_exp,$last_name)) {
 
    $error_message .= 'el formato del apellido no es válido.<br />';
 
  }
 
  if(strlen($message) < 2) {
 
    $error_message .= 'El formato del texto no es válido.<br />';
 
  }
 
  if(strlen($error_message) > 0) {
 
    die($error_message);
 
  }
 
//Este es el cuerpo del mensaje tal y como llegará al correo
 
    $email_message = "Contenido del Mensaje.\n\n";
 
 
 
    function clean_string($string) {
 
      $bad = array("content-type","bcc:","to:","cc:","href");
 
      return str_replace($bad,"",$string);
 
    }
 
 
 
    $email_message .= "Nombre: ".clean_string($first_name)."\n";
 
    $email_message .= "Teléfono: ".clean_string($last_name)."\n";
 
    $email_message .= "Email: ".clean_string($email_from)."\n";
 
    $email_message .= "solicitud: ".clean_string($telephone)."\n";
 
    $email_message .= "Mensaje: ".clean_string($message)."\n";
 
 
//Se crean los encabezados del correo
 
$headers = 'From: '.$email_from."\r\n".
 
'Reply-To: '.$email_from."\r\n" .
 
'X-Mailer: PHP/' . phpversion();
 
@mail($email_to, $email_subject, $email_message, $headers);
 
?>
 
 
 
<!-- Mensaje de que fue enviado-->
 
Gracias! Nos pondremos en contacto contigo
 
<?php
 
}
 
?>
<!-- Formulario de contacto -->

<div class="formulario">
   <div class="container">
   <h1 class="text-center"><b>CONTACTANOS</b></h1><br>
        <div class="row">
            <div class="col-12 col-md-4 col-md-offset-2">
            <form action="js/send_form_email.php">
              <div class="form-group">
                <label for="nombre">Nombre</label>
                <input type="email" class="form-control input-border" id="email" placeholder="" name="email">
              </div>
              <div class="form-group">
                <label for="telefono">Telefóno:</label>
                <input type="password" class="form-control input-border" id="pwd" placeholder="" name="pwd">
              </div>
              <div class="form-group">
                <label for="email">Correo</label>
                <input type="email" class="form-control input-border" id="email" placeholder="" name="email">
              </div>
              
              <label for="solicitud">Tipo de solicitud</label>
              <select class="form-control input-border">
              <option>Cotizar un servicio</option>
              <option>Agendar un servicio</option>
              <option>Unirse al equipo de trabajo</option>
              <option>Otras solicitudes</option>
              </select>

          </form>
          </div>

      <div class="col-12 col-md-4">
          <label for="message">Comentario</label>
          <textarea class="form-control input-border" rows="9"></textarea> 
          <br><br>
          <div class="pull-right">
             <div class="form-inline">
                <label for="pwd">Cargar archivo</label>
                <button type="submit" class="btn btn-default">Seleccionar Archivo</button>
             </div>
          </div>
      </div>

      <div class="row">
        <div class="col-12 col-md-10">
          <button type="submit" class="btn btn-default pull-right input-border boton-enviar">ENVIAR</button>
        </div>
      </div>   

  </div>   
 </div>
</div>
    
asked by linjai 22.09.2017 в 18:13
source

1 answer

1

you are missing the main thing:

You need to nest your elements within a form with an action tag:

<form action="/action_page.php" method="get">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  <input type="submit" value="Submit">
</form>

Link

    
answered by 22.09.2017 / 18:21
source