ERROR 500 when sending php form [closed]

2

It's burning my head !!! when I send a php form I get "ERROR 500" instead of sending it .... I share the code to see if someone finds what I do not: (

html code:

<div id="contact_form">
  <form action="contact.php" id="form1" name="form1" method="post">
    <div id="closeForm" onClick="displayFormContact('none')"></div>
      <figure id="logo_mensaje"></figure>
      <p>Como puedo ayudarte?</p>

      <input type="text" id="name" name="name" placeholder="Tu nombre">
      <input type="text" id="email" name="email" placeholder="Tu email">
      <textarea name="message" id="message" cols="30" rows="1" placeholder="Escribe aqui tu mensaje"></textarea>
      <input type="submit" name="submit" id="buttonEnviar" value="ENVIAR">
  </form>
</div>

php (name: contact.php) located in the same folder as the index.html:

<?php
   $para = '[email protected], [email protected]';

   $asunto = "mensaje de la web de el punto!!!!!!!!!!!!";

   $mailheader = "From: ".$_POST["email"]."\r\n";
   $mailheader .= "Reaply-To:".$_POST["email"]."\r\n";
   $mailheader .= "Content-type: text/html; charset=utf-8\r\n";

   $MESSAGE_BODY = "Nombre: ".$_POST["name"]."\n";
   $MESSAGE_BODY .= "\n<br>Email: ".$_POST["email"]."\n";
   $MESSAGE_BODY .= "\n<br>Mensaje: ".n12br($_POST["message"])."\n";

   mail($para, $asunto, $MESSAGE_BODY, $mailheader) or die("error al enviar mensaje, intente nuevamente")
   header("Location: http://graficaelpunto.com/web")
?>

If you want to see what happens the web is

graficaelpunto.com/web

Thank you very much for your contributions

    
asked by Fernanda 23.08.2018 в 15:09
source

1 answer

1

Error 500 occurs when something is wrong with the server. I think it's because of this: n12br . The function is called nl2br (you have a 1, and it must be one l, one letter ele).

Also, you should write a more elegant code, using variables to not write so much POST and write everything uniform: o \n o <br> or even better if you use PHP_EOL .

We will correct the error and improve the code:

<?php
   /*Capturamos las variables del POST con operadores ternarios*/
   $email=   ( empty($_POST["email"])   )  ?  NULL : $_POST["email"];
   $name=    ( empty($_POST["name"])    )  ?  NULL : $_POST["name"];
   $message= ( empty($_POST["message"]) )  ?  NULL : $_POST["message"];
   /*Verificamos que los tres datos fueron posteados*/
   if ($email && $name && $message){
       $para = '[email protected], [email protected]';
       $asunto = "mensaje de la web de el punto!!!!!!!!!!!!";
       $mailheader = "From: ".$email."\r\n";
       $mailheader .= "Reaply-To:".$email."\r\n";
       $mailheader .= "Content-type: text/html; charset=utf-8\r\n";

       $MESSAGE_BODY = "Nombre: ".$name."\n";
       $MESSAGE_BODY .= "\n<br>Email: ".$email."\n";
       $MESSAGE_BODY .= "\n<br>Mensaje: ".nl2br($message)."\n";

       mail($para, $asunto, $MESSAGE_BODY, $mailheader) or die("error al enviar mensaje, intente nuevamente");
       header("Location: http://graficaelpunto.com/web");

   }else{
        //Aquí puedes también redirigir con un mensaje de error
        echo "Error, no se postearon los datos necesarios";
  }
?>
    
answered by 23.08.2018 в 15:44