PHP - problema con codigo de formulario

 
Vista:

problema con codigo de formulario

Publicado por Jordi (8 intervenciones) el 27/08/2012 11:24:59
Buenos dias.
Tengo un problema con el codigo de envio de formulario, pues me aparecen en lugar de saltos de linea, la etiqueta html <br> y en lugar de los acentos, aparene el signo ?.
he comprobado en otros formularios semejantes realizados con el mismo codigo y no me da estos errores.
os dejo los codigos de la pagina del formulero en si mismo y el codigo php que lo procesa y envia a ver si vosotros me podeis dar la solucion pues he probado varias soluciones y una de las dos o no lo pongo bien (nl2br) o no funciona en este caso y si escribo por ejemplo en logar de é &eacute; me escribe esto ultimo.

gracias , aqui os dejo el codigo de ambas paginas.

pagina del formulario.

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
<?php
$num1 = rand(12,27);
$num2 = rand(3,18);
session_start();
$_SESSION['numero1'] = $num1;
$_SESSION['numero2'] = $num2;
?>
<!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">
 
// aqui irian las meta etiquetas de indexacion para google //
 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<script type="text/JavaScript">
<!--
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' debe ser una direccion de email correcta.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' debe ser un valor numérico.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' valor requerido.\n'; }
  } if (errors) alert('Hemos detectado los errores siguientes:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-34236386-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

// el formulario en cuestion //

<center>
                                    <span class="Estilo14"><span class="explicacion Estilo2"><br />
                                    <span class="Estilo6">Debe rellenar todos los datos para ponernos en contacto con usted. Gracias. </span></span><br />
                                    <br />
                                    </span>
                                </center></td>
                              </tr>
                              <tr>
                                <td><form id="form1" name="form1" method="post" action="envio.php">
                                    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                                      <tr>
                                        <td width="23%" height="30" valign="baseline"><div align="right"><span class="Estilo23"><strong>Nombre : </span></div></td>
                                        <td width="77%"><label>
                                          <div align="left">
                                              <input name="nombre" type="text" id="nombre" size="22" style="background-color:#88d8fd" />
                                              </label>
                                          </div></td>
                                      </tr>
                                      <tr>
                                        <td width="23%" height="30" valign="baseline"><div align="right" ><span class="Estilo23">Apellidos&nbsp; : </span></div></td>
                                        <td width="77%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                            <tr>
                                              <td><div align="left">
                                                  <label>
                                                  <input name="apellidouno" type="text" id="apellidouno" size="15" style="background-color:#88d8fd" />
                                                  </label>
                                                  <input name="apellidodos" type="text" id="apellidodos" size="15" style="background-color:#88d8fd" />
                                                </div>
                                                  <div align="left">
                                                    <label></label>
                                                </div></td>
                                            </tr>
                                        </table></td>
                                      </tr>
                                      <tr>
                                        <td width="23%" height="30" valign="baseline"><div align="right" class="Estilo23"><strong> e-mail&nbsp; : </span></strong></div></td>
                                        <td width="77%"><label>
                                            <div align="left">
                                              <input name="email" type="text" id="email" size="40" maxlength="100" style="background-color:#88d8fd" />
                                            </div>
                                          </label></td>
                                      </tr>
                                      <tr>
                                        <td height="8" colspan="2" valign="bottom"><img src="imagenes/spacer.gif" alt="spacer" width="1" height="1" /></td>
                                      </tr>
                                      <tr>
                                        <td width="23%" height="30" valign="top"><div align="right" class="Estilo23"> consulta&nbsp; : </span></div></td>
                                        <td width="77%"><div align="left">
                                            <label>
                                            <textarea name="comentario" cols="34" rows="6" id="comentario" style="background-color:#88d8fd"></textarea>
                                            </label>
                                        </div></td>
                                      </tr>
                                      <tr>
                                        <td width="23%" height="30"><div align="right"><strong><span class="Estilo23">antispam: </span></strong></div></td>
                                        <td width="77%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                            <tr>
                                              <td width="11%"><div align="right"><? echo ($num1); ?></div>
                                                  <div align="right"></div>
                                                <div align="right"></div></td>
                                              <td width="9%"><div align="center"><strong>+</strong></div></td>
                                              <td width="9%"><div align="left"><? echo ($num2); ?></div></td>
                                              <td width="7%"><div align="left"><strong>=</strong></div></td>
                                              <td width="64%" valign="top"><label> </label>
                                                  <label>
                                                  <div align="left">
                                                     &nbsp;<span class="Estilo10">Respuesta :</span>
                                                     <input name="respuesta" type="text" id="respuesta" size="4" maxlength="2" style="background-color:#88d8fd" />
                                                  </div>
                                                </label></td>
                                            </tr>
                                        </table></td>
                                      </tr>
                                      <tr>
                                        <td width="23%" height="30"><label>
                                            <div align="right">
                                              <input name="esborrar" type="reset" id="esborrar" value="Borrar" style="background-color:#88d8fd" />
                                            </div>
                                          </label></td>
                                        <td width="77%" valign="bottom"><label>
                                            <div align="right">
                                              <input name="Submit" type="submit" style="background-color:#88d8fd" onclick="MM_validateForm('nombre','','R','apellidouno','','R','apellidodos','','R','email','','RisEmail','respuesta','','NisNum','comentario','','R');return document.MM_returnValue" value="Enviar Formulario"/>
                                            </div>
                                          </label></td>
                                      </tr>
                                      <tr>
                                        <td width="23%" height="30">&nbsp;</td>
                                        <td width="77%">&nbsp;</td>
                                      </tr>
                                    </table>
                                  <img src="imagenes/spacer.gif" alt="spacer" width="1" height="1" />
                                </form></td>
                              </tr>


este es el codigo PHP para procesar el formulario :

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
<?php
session_start();
$num1=$_SESSION['numero1'];
$num2=$_SESSION['numero2'];
$sumval = $num1 + $num2;
$numval=$_POST['respuesta'];
 
if ($sumval == $numval)
{
$email=$_POST['email'];
$consulta=$_POST['comentario'];
 
$nombre=$_POST['nombre'];
$apellidouno=$_POST['apellidouno'];
$apellidodos=$_POST['apellidodos'];
$empresa='formulario@miweb.com';
$header .='From:'.$empresa."\r\n";
	$header .= "X-Mailer: PHP/" . phpversion() . " \r\n";
	$header .= "Mime-Version: 1.0 \r\n";
	$header .= "Content-Type text/plain ";
	$mensaje .= "e-mail remitido por :" .  "  " . $nombre. "    ". $apellidouno. "  ". $apellidodos ."\r\n";
	$mensaje .= "Enviado el dia " . date('d/m/Y');
	$mensaje .= " " . "\r\n";
	$mensaje .= " " . "\r\n";
	$mensaje .= " " . "Con la dirección de EMAIL de contacto :" . " " . $email." \r\n";
	$mensaje .= " " . "\r\n";
	$mensaje .= " " . "\r\n";
	$mensaje .= "Su consulta ha sido... :" .$consulta . "\r\n";
	$mensaje .= "  le damos las gracias por su atención, confianza y por el interes en nuestros productos"."\r\n";
	$mensaje .= " En breve contactaremos con usted para darle una respuesta."."\r\n";
	$mensaje .= " " . "\r\n";
	$mensaje .= "gracias" . "\r\n";
 
	$asunto= 'solicitud de contacto via formulario';
 
	mail($email, $asunto, utf8_decode ($mensaje), $header);
				$asunto='Copia de solicitud de contacto';
				mail($empresa, $asunto, utf8_decode ($mensaje), $header);
 
				  echo('<script language="JavaScript" >');
    echo('alert(" Su solicitud de contacto ha sido procesada correctamente\n Le ha sido remitido un email de confirmacion a la direccion de e-mail que nos ha facilitado.\n en breve nos pondremos en contacto con usted. \n Gracias.");');
    echo('location.replace("http://www.miweb.com/index.php")');
    echo('</script>');
}
else
{
    echo('<script language="JavaScript" >');
    echo('alert(" !!  A T E N C I O N   !! \n Su solicitud ..NO..  se ha podido procesar: \n por favor revise el formulario y responda a todos los campos incluido el anti-spam.\n Gracias por su colaboracion.");');
    echo('location.replace("http://www.miweb.com/contacto.php")');
    echo('</script>');
}
?>


espero podais ayudarme.
gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

problema con codigo de formulario

Publicado por Jordi (1 intervención) el 28/08/2012 10:20:34
Hola.
Bueno gracias a todos los que me habeis leido, aunque ya encontre el problema y está resuelto.
se trataba solamente de eliminar los utf decode y añadir al text/plain la codificacion iso y tema resuelto.
gracias.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar