A la hora de sumar un formulario de contacto a tu sitio web, es fundamental que el mismo evite vulnerabilidades que permitan a un tercero con malas intenciones tomar control de tus archivos para generar envíos de SPAM o alojar contenido malicioso. Te ofrecemos un ejemplo de cómo debería ser tu formulario.
Si vas a crear un formulario en PHP, deberás subir dos archivos al servidor para ponerlo online: uno que contenga el formulario tal cual deseas que se muestre en tu web y otro que genere la acción de llevar la información cargada en el formulario por tus visitantes a tu casilla de correo.
Generaremos un archivo html. En nuestro ejemplo, se llamará contacto.html.
|
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
<head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>CONTACTO</title></head><body> <td height="15"><div align="center"> <div align="center"> <FORM action="enviar.php" method="post" enctype="multipart/form-data" name="contacto" target="_top"> <table width="653" height="370" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="72" class="style7"><span class="style7">Nombre</span> </td> <td width="247" height="18" class="style7"><input name="Nombre" type="text" id="Nombre"></td> <td colspan="2" rowspan="2" class="style7"> </td> </tr> <tr> <td class="style7"> </td> <td class="style7"> </td> </tr> <tr> <td class="style7">E-mail</td> <td class="style7"><input name="Email" type="text" id="Email"></td> <td colspan="2" valign="bottom" class="style7"><div align="left" class="style24"></div></td> </tr> <tr> <td class="style7"> </td> <td class="style7"> </td> <td colspan="2" valign="middle" class="style7"><table width="387" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="24"> </td> <td width="100" class="style9"> </td> <td width="24" class="style9"> </td> <td width="102" class="style9"> </td> <td width="24" class="style9"> </td> <td width="113" class="style9"> </td> </tr> </table></td> </tr> <tr> <td class="style7">Teléfono</td> <td class="style7"><input name="Teléfono" type="text" id="Teléfono"></td> <td colspan="2" valign="bottom" class="style7"> </td> </tr> <tr> <td class="style7"> </td> <td class="style7"> </td> <td colspan="2" valign="bottom" class="style7"><table width="387" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="24"> </td> <td width="100" class="style9"> </td> <td width="24" class="style9"> </td> <td width="102" class="style9"> </td> <td width="24" class="style9"> </td> <td width="113" class="style9"> </td> </tr> </table></td> </tr> <tr> <td class="style7">Dirección</td> <td class="style7"><input name="Dirección" type="text" id="Dirección"></td> <td colspan="2" valign="bottom" class="style7"> </td> </tr> <tr> <td class="style7"> </td> <td class="style7"> </td> <td colspan="2" class="style7"><table width="387" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="24"> </td> <td width="100" class="style9"> </td> <td width="24" class="style9"> </td> <td width="102" class="style9"> </td> <td width="24" class="style9"> </td> <td width="113" class="style9"> </td> </tr> </table></td> </tr> <tr> <td class="style7">Localidad</td> <td class="style7"><input name="Localidad" type="text" id="Localidad"></td> <td colspan="2" class="style7"> </td> </tr> <tr> <td class="style7"> </td> <td class="style7"> </td> <td width="181" rowspan="3" class="style7"><div align="center"></div> <div align="center"></div></td> <td width="186" rowspan="3" class="style7"> </td> </tr> <tr> <td class="style7">Provincia</td> <td class="style7"><input name="Provincia" type="text" id="Provincia"></td> </tr> <tr> <td class="style7"> </td> <td class="style7"> </td> </tr> <tr> <td class="style7"><div align="center">Comentarios</div> <div align="center"></div></td> <td class="style7"><textarea name="Comentarios" cols="35" rows="4" id="Comentarios"></textarea></td> <td width="181" class="style7"> </td> <td valign="bottom" class="style7"> </td> </tr> <tr> <td height="54"> </td> <td><span class="style7"> <input name="Enviar" type="submit" class="style24" id="Enviar" onClick="return Enviar(this.form)" value="Enviar Presupuesto"> </span></td> <td colspan="2"><div align="center"></div></td> </tr> </table> <table width="468" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="249"> </td> <td width="219"><div align="center"></div></td> </tr> </table> <label><br> </label> </form> </div></td> </tr> <tr> <td height="15"> </td> </tr> <tr> <td height="30"> </td> </tr> </table> </td> </tr> <tr> <td height="65"> </td> </tr> </table> </td> </tr> </table></div></body></html> |
En el navegador se verá así:
El segundo archivo será un archivo PHP. En nuestro ejemplo, se llamará enviar.php.
|
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
|
<?$MailToAddress = "CUENTA_DE_CORREO";$MailSubject = "ASUNTO"; if (!$MailFromAddress) { $MailFromAddress = "CUENTA_DE_CORREO"; }$Header = "CONTACTO";$Footer = ""; if (!is_array($HTTP_POST_VARS)) return; reset($HTTP_POST_VARS); while(list($key, $val) = each($HTTP_POST_VARS)) { $GLOBALS[$key] = $val; $val=stripslashes($val); $Message .= "$key = $val\n"; } if ($Header) { $Message = $Header."\n\n".$Message."\n\n"; } $Message .= "REMOTE HOST: ".$REMOTE_HOST."\n"; $Message .= "REMOTE USER: ". $REMOTE_USER."\n"; $Message .= "REMOTE ADDR: ". $REMOTE_ADDR."\n"; if ($Footer) { $Message .= "\n\n".$Footer; }mail( "$MailToAddress", "$MailSubject", "$Message", "From: $MailFromAddress");header ("Location: http://DOMINIO/CONFIRMACION_DE_RECEPCION");?> |
Deberás editarlo para agregarle los datos correspondientes a tu sitio web y cuentas de correo:
|
1
|
$MailToAddress = "CUENTA_DE_CORREO"; |
Aquí, deberás modificar CUENTA_DE_CORREO por la dirección de mail a la que quieres recibir el contenido del formulario. Por ejemplo: consultas@misitio.com.
|
1
|
$MailSubject = "ASUNTO"; |
Reemplaza ASUNTO por el asunto con que llegarán todos los envíos de tu formulario. Por ejemplo, Nueva consulta.
|
1
|
$MailFromAddress = "CUENTA_DE_CORREO"; |
En esta línea reemplaza CUENTA_DE_CORREO por la dirección de mail que se utilizará como emisora de los correos generados por el formulario. Debe ser una cuenta creada desde tu panel Ferozo. Por ejemplo, feed@sitio.com.
|
1
|
header ("Location: http://DOMINIO/CONFIRMACION_DE_RECEPCION"); |
Por último, reemplaza http://DOMINIO/CONFIRMACION_DE_RECEPCION por la URL de la página donde agradeces a tus visitantes por completar el formulario. Por ejemplo:http://sitio.com/formulario_enviado.php.