Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/06/2017, 06:55
macaluan
 
Fecha de Ingreso: junio-2014
Mensajes: 70
Antigüedad: 9 años, 10 meses
Puntos: 0
Botón de envio no funciona en formulario

Hola,

tengo este formulario de e-mail, pero después de rellenar los datos, no consigo que el botón enviar funcione. No es que de error, es que directamente no funciona.


Código HTML:
Ver original
  1. <form class="form-contact animate-box col-md-8 col-md-offset-2 text-center section-heading" method="post" action="sendbymail.php">
  2.                         <div class="animate-box"><input type="text" value="Your name" onFocus="if (this.value=='Your name') this.value='';"></div>
  3.                         <div class="animate-box"><input type="text" value="Your E-mail" onFocus="if (this.value=='Your E-mail') this.value='';"></div>
  4.                         <div class="animate-box"><input type="text" value="Subject" onFocus="if (this.value=='Subject') this.value='';"></div>
  5.                         <div class="animate-box"><textarea rows="6"> Comments </textarea></div>
  6.                         <div class="animate-box"><input type="button" class="button" value="Send" /></div>
  7.                     </form>


Código PHP:
Ver original
  1. <!doctype html>
  2.  
  3. <html>
  4. <head>
  5. <meta charset="UTF-8">
  6. <title></title>
  7. </head>
  8.  
  9. <body>
  10. <?php
  11. if(isset($_POST['email'])) {
  12.  
  13.     // Edita las dos líneas siguientes con tu dirección de correo y asunto personalizados
  14.  
  15.     $email_to = "";
  16.     $email_subject = "Tu Asunto de correo";  
  17.  
  18.     function died($error) {
  19.  
  20.         // si hay algún error, el formulario puede desplegar su mensaje de aviso
  21.  
  22.         echo "Sorry, there was an error in your data and the e-mail can not be sent at this time. ";
  23.  
  24.         echo "Detail of the errors.<br /><br />";
  25.        
  26.         echo $error."<br /><br />";
  27.  
  28.         echo "Please, correct these errors and try again.<br /><br />";
  29.         die();
  30.     }
  31.  
  32.     // Se valida que los campos del formulairo estén llenos
  33.  
  34.     if(!isset($_POST['first_name']) ||
  35.  
  36.         !isset($_POST['last_name']) ||
  37.  
  38.         !isset($_POST['email']) ||
  39.  
  40.         !isset($_POST['telephone']) ||
  41.  
  42.         !isset($_POST['message'])) {
  43.  
  44.         died('Sorry, but there seems to be a problem with the data.');      
  45.  
  46.     }
  47.  //En esta parte el valor "name" nos sirve para crear las variables que recolectaran la información de cada campo
  48.    
  49.     $first_name = $_POST['first_name']; // requerido
  50.  
  51.     $last_name = $_POST['last_name']; // requerido
  52.  
  53.     $email_from = $_POST['email']; // requerido
  54.  
  55.     $telephone = $_POST['telephone']; // no requerido
  56.  
  57.     $message = $_POST['message']; // requerido
  58.  
  59.     $error_message = "Error";
  60.  
  61. //En esta parte se verifica que la dirección de correo sea válida
  62.    
  63.    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  64.  
  65.   if(!preg_match($email_exp,$email_from)) {
  66.  
  67.     $error_message .= 'Sorry, the email address provided is invalid.<br />';
  68.  
  69.   }
  70.  
  71. //En esta parte se validan las cadenas de texto
  72.  
  73.     $string_exp = "/^[A-Za-z .'-]+$/";
  74.  
  75.   if(!preg_match($string_exp,$first_name)) {
  76.  
  77.     $error_message .= 'Sorry, the format of the name is not valid.<br />';
  78.  
  79.   }
  80.  
  81.   if(!preg_match($string_exp,$last_name)) {
  82.  
  83.     $error_message .= 'Sorry, the surname format is not valid.<br />';
  84.  
  85.   }
  86.  
  87.   if(strlen($message) < 2) {
  88.  
  89.     $error_message .= 'Sorry, the format of the text is not valid.<br />';
  90.  
  91.   }
  92.  
  93.   if(strlen($error_message) > 0) {
  94.  
  95.     died($error_message);
  96.  
  97.   }
  98.  
  99. //A partir de aqui se contruye el cuerpo del mensaje tal y como llegará al correo
  100.  
  101.     $email_message = "Contenido del Mensaje.\n\n";
  102.  
  103.      
  104.  
  105.     function clean_string($string) {
  106.  
  107.       $bad = array("content-type","bcc:","to:","cc:","href");
  108.  
  109.       return str_replace($bad,"",$string);
  110.  
  111.     }
  112.  
  113.      
  114.  
  115.     $email_message .= "Nombre: ".clean_string($first_name)."\n";
  116.  
  117.     $email_message .= "Apellido: ".clean_string($last_name)."\n";
  118.  
  119.     $email_message .= "Email: ".clean_string($email_from)."\n";
  120.  
  121.     $email_message .= "Teléfono: ".clean_string($telephone)."\n";
  122.  
  123.     $email_message .= "Mensaje: ".clean_string($message)."\n";
  124.  
  125.  
  126. //Se crean los encabezados del correo
  127.  
  128. $headers = 'From: '.$email_from."\r\n".
  129.  
  130. 'Reply-To: '.$email_from."\r\n" .
  131.  
  132. 'X-Mailer: PHP/' . phpversion();
  133.  
  134. @mail($email_to, $email_subject, $email_message, $headers);  
  135.  
  136. ?>
  137.  
  138.  
  139.  
  140. <!-- incluye aqui tu propio mensaje de Éxito-->
  141.  
  142. Done! Thank you for your interest, I will send you an answer as soon as possible.
  143.  
  144. <?php
  145.  
  146. }
  147.  
  148. ?>
  149. </body>
  150. </html>