Como hacer un Formulario

>> //seccion/php/ -- 0 comentario /// Agregado el 2003-09-08 @ Por Edan

En este Tutorial veremos como hacer un formulario php para nuestra pagina...

Script :

Para ellos utilizaremos la función mail() para poder enviar emails desde una página PHP.

Este archivo (formulario.htm) es un simple formulario con 4 campos:
Code:


 <form method="post" action="recomendar.php">
 <table width="55%" height="215" align="center" cellpadding="4" cellspacing="0">
 <tr>
 <td height="213" align="center" valign="top" >
 <p class="style2"><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Recomienda este sitio a un amigo</b></font></p>
 <p class="style2"><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Tu nombre:</b>
 <input type="text" name="tunombre2" size="20">
 
 <b> Tu email:</b>
 <input type="text" name="tuemail2" size="20">
 
 <b>Nombre de tu amigo:</b>
 <input type="text" name="nombreamigo2" size="20">
 
 <b>Email de tu amigo:</b>
 <input type="text" name="emailamigo2" size="20">
 
 <input type="submit" value="Recomendar" name="B12">
 </font></p>
 
 </td>
 </tr>
 </table>
 </form>
 


Codigo Completo
Codigo:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
//<form method="POST" action="recomendar.php"> 
//<p>Recomienda este sitio a un amigo:</p> 
//<p>Tu nombre: 
// 

//<input type="text" name="tunombre" size="20"> 
//Tu email: 
// 

//<input type="text" name="tuemail" size="20"> 
//Nombre de tu amigo: 
//<input type="text" name="nombreamigo" size="20"> 
//Email de tu amigo: 
//<input type="text" name="emailamigo" size="20"> 
// 
//<input type="submit" value="Recomendar" name="B1"> 
//</p> 
//</form> 

//Recomendando a un amigo: 
//El archivo recomendar.php es el encargado de procesar el formulario y realizar el envío del mail. 
//El código y su explicación son los siguientes: recomendar.php 

// Completamos la variable $asunto con el título del mensaje 
// y armamos el mensaje dentro de la variable $mensaje 

$asunto "Un amigo te recomienda MCTEKK.com"

$mensaje "Hola ".$nombreamigo.", tu amigo ".$tunombre.
              recomienda que ingreses al sitio www.mctekk.com, 
              en el cual podrás encontrar gran cantidad de info para webmasters."


// Utilizamos la función mail() de PHP para realizar el envío del mensaje 

mail($emailamigo$asunto$mensaje"From: ".$tuemail); 

//<html> 
//<head> 
//<title> 
//Recomendarnos 
//</title> 
//</head> 
//<body> 
//Muchas gracias por recomendarnos. 
//</body> 
//</html> 

?>


ahora debes modificar el mensaje, la página de agradecimiento, y estarás listo para utilizarlo en tu sitio.