Ver Mensaje Individual
  #5 (permalink)  
Antiguo 09/09/2009, 23:31
MikelelToro
 
Fecha de Ingreso: diciembre-2008
Mensajes: 11
Antigüedad: 15 años, 4 meses
Puntos: 0
Respuesta: No me funciona Formulario de contacto

Hola, primero agradaceros la rapidez con la que habeis contestado.
Aqui os mando el formulario que encontre en internet y que funciona correctamente:

<?php
$to='fulano_detal_tudomain.com';
$messageSubject='contacto';
$confirmationSubject='En breve nos pondremos en contacto';
$confirmationBody="Gracias por contactar";
$email='';
$body='';
$displayForm=true;
if ($_POST){
$email=stripslashes($_POST['email']);
$body=stripslashes($_POST['body']);
// validate e-mail address
$valid=eregi('^([0-9a-z]+[-._+&])*[0-9a-z]+@([-0-9a-z]+[.])+[a-z]{2,6}$',$email);
$crack=eregi("(\r|\n)(to:|from:|cc:|bcc:)",$body);
if ($email && $body && $valid && !$crack){
if (mail($to,$messageSubject,$body,'From: '.$email."\r\n")
&& mail($email,$confirmationSubject,$confirmationBody .$body,'From: '.$to."\r\n")){
$displayForm=false;
?>
</p>
<p> Su mensaje ha sido enviado correctamente.
El mensaje enviado dice lo siguiente: </p>
<?php
echo '<p>'.htmlspecialchars($body).'</p>';
}else{ // the messages could not be sent
?>
<p> Something went wrong when the server tried to send your message.
This is usually due to a server error, and is probably not your fault.
We apologise for any inconvenience caused. </p>
<?php
}
}else if ($crack){ // cracking attempt
?>
<p><strong> Your message contained e-mail headers within the message body.
This seems to be a cracking attempt and the message has not been sent. </strong></p>
<?php
}else{ // form not complete
?>
<p><strong> Your message could not be sent.
You must include both a valid e-mail address and a message. </strong></p>
<?php
}
}
if ($displayForm){
?>
<form action="" method="post">
<table>
<tr>
<td class="label"><label for="email">Su dirección de email</label></td>
<td><input type="text" name="email" id="email" value="<?php echo htmlspecialchars($email); ?>" size="30" />
</td>
</tr>
<tr>
<td class="label"><label for="body">Su mensaje</label></td>
<td><textarea name="body" id="body" cols="70" rows="5">
<?php echo htmlspecialchars($body); ?>
</textarea></td>
</tr>
<tr>
<td id="submit" colspan="2"><button type="submit">Enviar</button></td>
</tr>
</table>
</form>
<?php
}
?>



Si intento añadir otro campo, digamos "Nombre", consigo que me aparezca la información en la web, pero no me recoge la información. Además, con el formulario que expongo abajo, el primer intento siempre falla, pero al segundo, lo manda, pero sin el nombre.

Ideas ?

Lo que hago es esto:

<?php
$to='fulano_detal_tudomain.com';
$messageSubject='contacto';
$confirmationSubject='En breve nos pondremos en contacto';
$confirmationBody="Gracias por contactar";
$nombre='';
$email='';
$body='';
$displayForm=true;
if ($_POST){
$email=stripslashes($_POST['email']);
$nombre=stripslashes($_POST['nombre']);
$body=stripslashes($_POST['body']);
// validate e-mail address
$valid=eregi('^([0-9a-z]+[-._+&])*[0-9a-z]+@([-0-9a-z]+[.])+[a-z]{2,6}$',$email);
$crack=eregi("(\r|\n)(to:|from:|cc:|bcc:)",$body);
if ($email && $body && $nombre && $valid && !$crack){
if (mail($to,$messageSubject,$body,'From: '.$email."\r\n")
&& mail($email,$confirmationSubject,$confirmationBody .$body,'From: '.$to."\r\n")){
$displayForm=false;
?>
</p>
<p> Su mensaje ha sido enviado correctamente.
El mensaje enviado dice lo siguiente: </p>
<?php
echo '<p>'.htmlspecialchars($body).'</p>';
}else{ // the messages could not be sent
?>
<p> Something went wrong when the server tried to send your message.
This is usually due to a server error, and is probably not your fault.
We apologise for any inconvenience caused. </p>
<?php
}
}else if ($crack){ // cracking attempt
?>
<p><strong> Your message contained e-mail headers within the message body.
This seems to be a cracking attempt and the message has not been sent. </strong></p>
<?php
}else{ // form not complete
?>
<p><strong> Your message could not be sent.
You must include both a valid e-mail address and a message. </strong></p>
<?php
}
}
if ($displayForm){
?>
<form action="" method="post">
<table>
<tr>
<td class="label"><label for="email">Su dirección de email</label></td>
<td><input type="text" name="email" id="email" value="<?php echo htmlspecialchars($email); ?>" size="30" />
</td>
<td class="label"><label for="nombre">Su Nombre</label></td>
<td><input type="text" name="nombre" id="nombre" value="<?php echo htmlspecialchars($nombre); ?>" size="30" />
</td>

</tr>
<tr>
<td class="label"><label for="body">Su mensaje</label></td>
<td><textarea name="body" id="body" cols="70" rows="5">
<?php echo htmlspecialchars($body); ?>
</textarea></td>
</tr>
<tr>
<td id="submit" colspan="2"><button type="submit">Enviar</button></td>
</tr>
</table>
</form>
<?php
}
?>

Muchas gracias