> Faqs > Enviar formulario por email y a una págian php

Enviar formulario por email y a una págian php

Hola: Estoy diseñando un formulario básico que debe llegar al correo del destinatario. Fácil. Pero además quiero que si el correo llega, se abra una página php con los datos del formulario y que todo está correcto. Se que es un simple condicional, pero no veo la forma de afrontarlo. Si alguien sabe cómo, se lo agradeceré mucho.

Respuestas

Ya me respondo yo solo porque he encontrado la solución. Espero que a alguien le venga bien. Necesitamos dos archivos .php. Uno enviará la información a otro y éste la recibirá y la enviará por correo utilizando la función mail(), que no suele funcionar en alojamientos gratuitos. Cuelgo los códigos para que los veáis. Enviar.php (dentro de un <form>) <?php if (!$HTTP\_POST\_VARS){ ?> <p>Si quieres contactar con nosotros rellena el siguiente formulario y en breve te daremos una respuesta.</p> <form action="form.php" method="post"> <table summary="Formulario de contacto Yagüe F.C." width="96%" border="1"> <caption> Datos personales </caption> <tr> <th scope="row">Nombre:</th> <td><input type="text" id="nombre" name="nombre" size="40" /></td> </tr> <tr> <th scope="row">Apellidos:</th> <td><input type="text" id="apellidos" name="apellidos" size="40" /></td> </tr> <tr> <th scope="row">Dirección:</th> <td><input type="text" id="direccion" name="direccion" size="40" /></td> </tr> <tr> <th scope="row">Teléfono:</th> <td><input type="text" id="telefono" name="telefono" size="40" /></td> </tr> <tr> <th scope="row">Ciudad:</th> <td><input type="text" id="ciudad" name="ciudad" size="40" /></td> </tr> <tr> <th scope="row">E-mail:</th> <td><input type="text" id="correo" name="correo" size="40" /></td> </tr> <tr> <th valign="top" scope="row"><strong>Escribe aquí tus comentarios:</strong> <div style="margin-top:20%"> <input name="botón" type="submit" value="Enviar" /></div> </th> <td><textarea name="comentario" id="comentario" cols="40" rows="10"></textarea></td> </tr> </table> </form> <?php }else{ echo "Ha ocurrido un error"; } ?> Recibir.php <?php if ($HTTP\_POST\_VARS){ $\_POST\["nombre"\]=$nombre; $\_POST\["apellidos"\]=$apellidos; $\_POST\["direccion"\]=$direccion; $\_POST\["telefono"\]=$telefono; $\_POST\["ciudad"\]=$ciudad; $\_POST\["correo"\]=$correo; $\_POST\["comentario"\]=$comentario; ?> <strong>Nombre: </strong> <?php echo "$nombre";?><br/> <strong>Apellidos: </strong> <?php echo "$apellidos";?><br/> <strong>Dirección: </strong> <?php echo "$direccion";?><br/> <strong>Teléfono: </strong> <?php echo "$telefono";?><br/> <strong>Ciudad: </strong> <?php echo "$ciudad";?> <br/> <strong>E mail: </strong> <?php echo "$correo";?> <br/> <strong>Comentario:</strong> <?php echo "$comentario";?> </p> <?php $cuerpo .="Formulario del contacto"."<br />"; $cuerpo .="NOMBRE: ".$HTTP\_POST\_VARS\["nombre"\]." "."<br />"; $cuerpo .="APELLIDOS: ".$HTTP\_POST\_VARS\["apellidos"\]." "."<br />"; $cuerpo .="DIRECCIÓN: ".$HTTP\_POST\_VARS\["direccion"\]." "."<br />"; $cuerpo .="TELÉFONO: ".$HTTP\_POST\_VARS\["telefono"\]." "."<br />"; $cuerpo .="CIUDAD: ".$HTTP\_POST\_VARS\["ciudad"\]." "."<br />"; $cuerpo .="CORREO: ".$HTTP\_POST\_VARS\["correo"\]." "."<br />"; $cuerpo .="COMENTARIOS: ".$HTTP\_POST\_VARS\["comentarios"\]." "."<br />"; $headers="MIME-Version: 1.0 "; $headers.= "Content-type: text/html; charset=iso-8859-1 "; mail("direcciondedestino@loquesea.com","Formulario recibido",$cuerpo,$headers); }else{ echo "ALGO FALLA !!!!"; } ?>

vbox