Ver Mensaje Individual
  #4 (permalink)  
Antiguo 12/09/2012, 21:57
davy0324
 
Fecha de Ingreso: mayo-2012
Ubicación: Bogota
Mensajes: 45
Antigüedad: 12 años
Puntos: 0
Respuesta: Formulario php en cpanel

jajajajaj si es correcto lo siento aca dejo el codigo:

Código HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
	<title>PHP Contact Form with JQuery Validation</title>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<meta http-equiv="Content-Style-Type" content="text/css" />

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script src="jquery.validate.pack.js" type="text/javascript"></script>

<script type="text/javascript">
$(document).ready(function(){
	$("#contactform").validate();
});
</script>

<style type="text/css">
body {
	font-family:Arial, Helvetica, sans-serif;
}
#contact-wrapper {
	width:440px;
	background:#ffffff;
	padding:20px;
}
#contact-wrapper div {
	clear:both;
	margin:1em 0;
}
#contact-wrapper label {
	display:block;
	float:none;
	font-size:12px;
	width:auto;
	color:#555;
}
form#contactform input {
	font-family:Verdana, Geneva, sans-serif;
	border:1px solid #999;
	padding:5px;
	font-size:12px;
	color:#222;
	background-color:#FFF;
}
form#contactform textarea {
	font-family:Arial, Tahoma, Helvetica, sans-serif;
	font-size:100%;
	padding:0.6em 0.5em 0.7em;
	border:1px solid #999;
}

</style>
</head>

<body>
	<div id="contact-wrapper">

	<?php if(isset($hasError)) { //If errors are found ?>
		<p class="error"><font face="Arial, Helvetica, sans-serif" size="-1" color="#555">Please check if you've filled all the fields with valid information. Thank you.</font></p>
	<?php } ?>

	<?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
		<p><strong><font face="Verdana, Geneva, sans-serif" size="-1" color="#555">Email Successfully Sent!</font></strong></p>
		<p><font face="Arial, Helvetica, sans-serif" size="-1" color="#555">Thank you, Your email was successfully sent and I will be in touch with you soon.</font></p>
	<?php } ?>

	<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform">
		<div>
		    <label for="name"><strong>Name:</strong></label>
			<input type="text" size="36" name="contactname" id="contactname" value="" class="required" />
		</div>

		<div>
			<label for="email"><strong>Email:</strong></label>
			<input type="text" size="36" name="email" id="email" value="" class="required email" />
		</div>

		<div>
			<label for="subject"><strong>Subject:</strong></label>
			<input type="text" size="36" name="subject" id="subject" value="" class="required" />
		</div>

		<div>
			<label for="message"><strong>Message:</strong></label>
			<textarea rows="5" cols="36" name="message" id="message" class="required"></textarea>
		</div>
	    <input type="submit" value="Send Message" name="submit" />
	</form>
	</div>
</body>
</html> 
aqui esta el php:


Código PHP:
<?php
//If the form is submitted
if(isset($_POST['submit'])) {

    
//Check to make sure that the name field is not empty
    
if(trim($_POST['contactname']) == '') {
        
$hasError true;
    } else {
        
$name trim($_POST['contactname']);
    }

    
//Check to make sure that the subject field is not empty
    
if(trim($_POST['subject']) == '') {
        
$hasError true;
    } else {
        
$subject trim($_POST['subject']);
    }

    
//Check to make sure sure that a valid email address is submitted
    
if(trim($_POST['email']) == '')  {
        
$hasError true;
    } else if (!
eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$"trim($_POST['email']))) {
        
$hasError true;
    } else {
        
$email trim($_POST['email']);
    }

    
//Check to make sure comments were entered
    
if(trim($_POST['message']) == '') {
        
$hasError true;
    } else {
        if(
function_exists('stripslashes')) {
            
$comments stripslashes(trim($_POST['message']));
        } else {
            
$comments trim($_POST['message']);
        }
    }

    
//If there is no error, send the email
    
if(!isset($hasError)) {
        
$emailTo '[email protected]'//Put your own email address here
        
$body "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
        
$headers 'From: My Site <'.$emailTo.'>' "\r\n" 'Reply-To: ' $email;

        
mail($emailTo$subject$body$headers);
        
$emailSent true;
    }
}
?>