Jump to content

Ayuda con FORMULARIO porfa!


Recommended Posts

hola amigos, soy algo nuevo en php y siempre tengo problemas con los formularios de contacto. El punto es que tengo uno, que venia en una plantilla, y le hise las modificaciones necesarias pero no funca, los correos de prueba no me llegan y estoy provando desde el hosting, no en localhost.

 

Aqui el formulario

 

/////////////formulario /////////////////////////

<form action="contact.php" method="post" id="contactform">

<ol>

<li>

<label for="name">Nombre<span class="red">*</span></label>

<input id="name" name="name" class="text" />

</li>

<li>

<label for="email"> email <span class="red">*</span></label>

<input id="email" name="email" class="text" />

</li>

<li>

<label for="company">Empresa</label>

<input id="company" name="company" class="text" />

</li>

<li>

<label for="subject">Asunto</label>

<input id="subject" name="subject" class="text" />

</li>

<li>

<label for="message">Mensaje <span class="red">*</span></label>

<textarea id="message" name="message" rows="6" cols="50"></textarea>

</li>

<li class="buttons">

<input type="image" name="imageField" id="imageField" src="images/send.png" class="send" />

<div class="clr"></div>

</li>

</ol>

</form>

 

 

AQui el archivo contact.php

 

/////////////////////////////////////////////

<?php

 

if(!$_POST) exit;

 

$email = $_POST['email'];

 

 

//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'ERROR, DIRECCION MAIL NO VALIDA';

if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){

$error.="Ingresa un Mail valido o intenta con otro";

$errors=1;

}

if($errors==1) echo $error;

else{

$values = array ('name','email','message');

$required = array('name','email','message');

 

$your_email = "MAIL EDITADO";

$email_subject = "Nuevo Mensaje desde EDITADO : ".$_POST['subject'];

$email_content = "new message:\n";

 

foreach($values as $key => $value){

if(in_array($value,$required)){

if ($key != 'subject' && $key != 'company') {

if( empty($_POST[$value]) ) { echo 'LOS CAMPOS MARCADOS CON * SON OBLIGATORIOS'; exit; }

}

$email_content .= $value.': '.$_POST[$value]."\n";

}

}

 

if(@mail($your_email,$email_subject,$email_content)) {

echo 'MENSAJE ENVIADO CON EXITO!';

} else {

echo 'ERROR!';

}

}

?>

 

 

 

POR LA DUDA, el el archivo donde esta el formulario tambien hay este script

 

<script type="text/javascript">

// <![CDATA[

jQuery(document).ready(function(){

$('#contactform').submit(function(){

var action = $(this).attr('action');

$.post(action, {

name: $('#name').val(),

email: $('#email').val(),

company: $('#company').val(),

subject: $('#subject').val(),

message: $('#message').val()

},

function(data){

$('#contactform #submit').attr('disabled','');

$('.response').remove();

$('#contactform').before('<p class="response">'+data+'</p>');

$('.response').slideDown();

if(data=='Message sent!') $('#contactform').slideUp();

}

);

return false;

});

});

// ]]>

</script>

 

 

LA VERDAD< NO TENGO PICHULA IDEA QUE HACE ESTE SCRIPT. AYUDA PORFA! :tonto: :tonto:

Link to comment
Share on other sites

Mandale con este es mas simple:

 

<?php 
// INGRESE EL EMAIL DONDE RECIBIRÁ LOS DATOS DEL FOMULARIO
$para = '[email protected]'; 

$asunto = $_POST["tipo"]; 
$mailheader = "From: ".$_POST["email"]."\r\n"; 
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$MESSAGE_BODY = "Nombre: ".$_POST["nombre"]."<br>"; 
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"; 
$MESSAGE_BODY .= "Telefono: ".$_POST["telefono"]."<br>"; 
$MESSAGE_BODY .= "Tipo de contacto: ".$_POST["tipo"]."<br>";
$MESSAGE_BODY .= "Mensaje: ".nl2br($_POST["mensaje"])."<br>"; 
mail($para, $asunto, $MESSAGE_BODY, $mailheader) or die ("Error al enviar el Formulario !"); 

//MODIFICAR A LA DIRECCIÓN EN SU SERVIDOR
header( 'Location: http://www.SuSitio.com/gracias.html' )
?>


Link to comment
Share on other sites

Gracias ya lo arregle, era por la caga de hosting gratis donde estaba haciendo las pruebas, ademas al code le faltaba el header de mail.

 

Pero tengo otra duda, como hago para que cuando el envio del mail es exitoso me redirija a la pag de contacto pero que limpie el formulario, osea que cuando me redirija en formulario de contacto este vacio?????

 

Gracias por sus ayudas!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...