Ver Mensaje Individual
  #7 (permalink)  
Antiguo 23/03/2012, 04:45
szalenstwo
 
Fecha de Ingreso: octubre-2011
Mensajes: 25
Antigüedad: 12 años, 6 meses
Puntos: 0
Respuesta: formulario de contacto

Hola buenas apaxito!!

Estos son los cambios que acabo de hacer... no se lo he echo bien como lo tengo ahora.
Código PHP:
Ver original
  1. <?php
  2.  
  3.  if($_SERVER['REQUEST_METHOD'] == 'POST'){
  4.  
  5.  //First check that no field is empty and that all fields exist.
  6.  if(isset($_POST['name']) && !empty($_POST['name'])){
  7.  $name = mysql_real_escape_string($_POST['name']);
  8.  
  9.  }
  10.  
  11.  if(isset($_POST['email']) && !empty($_POST['email']))
  12.  {
  13.  $email = mysql_real_escape_string($_POST['email']);
  14.  
  15.  }
  16.  
  17.  if(isset($_POST['comment']) && !empty($_POST['comment'])){
  18.      $comment = mysql_real_escape_string($_POST['comment']);
  19.  
  20.  }
  21.  /*
  22.          // Complete error variable if necessary.
  23.          /*
  24.          {
  25.         if ( empty($nombre) ) $error['nombre']     ='It is obligatory to enter a name';
  26.         if ( empty($email) )    $error['email']      ='It is obligatory to enter a email';
  27.         if ( empty($comentario) ) $error['comentario'] ='It is obligatory to enter a comment';
  28.         }
  29.          */
  30.          
  31.  // If you entered is that everything is done correctly
  32.  
  33.  $link = mysql_connect("localhost", "root", "");
  34.  mysql_select_db("prueba",$link);
  35.  if($link) {
  36.       //echo "Connection completed successfully.";
  37.  
  38.   } else {  
  39.  
  40.     header( 'Location:error.php');
  41.  
  42.   }
  43.  
  44.  // insert data in database.
  45.  $sql = "INSERT INTO sumit(name, email, comment)
  46. VALUES('".$name."','".$email."','".$comment."',)";
  47.  
  48.      
  49.     if($name && $email && $comment) {
  50.    
  51.     $resultado = mysql_query($sql);
  52.        
  53.         if($resultado){
  54.        
  55.        
  56.         mandaMail($name, $email, $comment);
  57.        
  58.        
  59.         header( 'Location:informe.php?registro=true');
  60.         }
  61.  
  62. }else{
  63.  
  64.     header( 'Location:failed.php?registro=false');
  65.  
  66. }
  67. }
  68.  
  69.  function mandaMail ($name, $email, $comment){
  70.  
  71.     $mail='[email protected]';
  72.          
  73.        
  74.         # These data are to be seen in the mail
  75.         $cuerpo = "
  76.         name: ".$name."
  77.         email: ".$email."
  78.         comentario: ".$comment."";
  79.         # asunto del mensaje
  80.         if (mail($mail,"Oliver Arthur Webmaster",$cuerpo, "From: ".$name." <".$email.">"))
  81.         $header .= "X-Mailer: PHP/" . phpversion() . " \r\n";
  82.         $header .= "Mime-Version: 1.0 \r\n";
  83.         $header .= 'Content-type: text/plain; charset=utf-8' . "\r\n";
  84.         mail($to,$subject,$message,$headers);
  85.  }
  86.  ?>