Translate-Traducir

2/6/14

Enviar un formulario de contacto por email en PHP

Para no hacer el codigo muy largo la he dividido en 2 paginas


Esta seria la pagina  del formulario
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>formulario</title>
</head>
<body>
<center>
<h2>FORMULARIO DE CONTACTO</h2>
  <table width="500" border="0" bgcolor="#66CCFF">
  <form name="formulario" method="get" action="pagina.php">/*aqui poner la direccion de la pagina que envia*/
    <tr>
      <td width="100">Para    :</td>
      <td><input name="para" type="text" size="50" maxlength="25" required="required" /></td>
    </tr>
    <tr>
      <td width="100">Nombre :   </td>
      <td><input name="nombre" type="text" size="50" maxlength="25"  /></td>
    </tr>
    <tr>
      <td width="100">Apellidos :</td>
      <td><input name="apellido" type="text" size="50" maxlength="25"  /></td>
    </tr>
    <tr>
      <td width="100" >Direccion :</td>
      <td><input name="direccion" type="text" size="50" maxlength="25"  /></td>
    </tr>
    <tr>
      <td width="100" >Asunto :</td>
      <td><input name="asunto" type="text" size="50" maxlength="25" required="required" /></td>
    </tr>
    <tr>
      <td width="100" colspan="2">Sexo : Hombre<input name="Sexo" type="radio" value="Hombre" />
       Mujer<input name="Sexo" type="radio" value="Mujer" />
<br />
Seleccione provincia : <select name="provincia" size="1">
  <option>Valencia</option>
  <option>Castellon</option>
  <option>Alicante</option>
</select>
<br /><br />
 Acepto las condiciones :<input name="acepto" type="checkbox" value="" required="required" />
 <p align="center">Mensaje </p><br />
<center> <textarea name="mensaje" cols="50" rows="10"></textarea></center><br />
<center><input name="enviar" type="submit" value="Enviar datos" /></center></td>
   
          </tr>
    </form>
   </table>
  </center>
 </body>
</html>
////////////////////////////////////////////////////////////////////////////////
 Y esta seria la pagina que envia 
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Pagina envio de datos</title>/*No confundir con la pagina esto es solo el titulo*/
</head>
<body>
<?php
if(isset($_REQUEST["enviar"])){

if(isset($_REQUEST["para"])){
  if(isset($_REQUEST["acepto"])){
 $nombre=$_REQUEST["nombre"];

      $apellido=$_REQUEST["apellido"];
      $provincia=$_REQUEST["provincia"];
      $Sexo=$_REQUEST["Sexo"];
      $direccion=$_REQUEST["direccion"];

 $mensaje=$_REQUEST["mensaje"];
$para=$_REQUEST["para"];
$asunto=$_REQUEST["asunto"];
$todo=("Nombre :".$nombre."\n".
"Apellido :".$apellido."\n".
"Provincia :".$provincia."\n".
"Direccion :".$direccion."\n".
 "Sexo :".$Sexo."\n".
 "Mensaje :".$mensaje."\n");


  mail($para,$asunto,$todo);
      echo "Su mensaje a sido enviado correctamente.";
   }
  }
 }else{

echo "Faltan campos por rellenar";

     }
?>
</body>
</html>

No hay comentarios: