Si me pueden orientar en qué puedo estar haciendo mal les estaré infinitamente agradecido!
--------------------------------------------
contacto.html
--------------------------------------------
Código HTML:
<form method="post" action="contacto.php" id="cForm"> <fieldset> <label for="posName">Nombre</label><br /> <input class="input" type="text" size="25" name="posName" id="posName" /><br /><br /> <label for="posEmail">Email</label><br /> <input class="input" type="text" size="25" name="posEmail" id="posEmail" /><br /><br /> <label for="posRegard">Asunto</label><br /> <input class="input" type="text" size="25" name="posRegard" id="posRegard" /><br /><br /> <label for="posText">Mensaje</label><br /> <textarea cols="50" rows="5" name="posText" id="posText" class="textarea"></textarea><br /><br /> <label for="selfCC"> <!--<input type="checkbox" name="selfCC" id="selfCC" value="send" /> Send CC to self--> <input type="hidden" name="selfCC" id="selfCC" value="xxx" /> </label> <input class="input-submit" type="image" name="sendContactEmail" id="sendContactEmail" value=" " /> </fieldset> </form> </div>
--------------------------------------------
contacto.php
--------------------------------------------
Código PHP:
<?php
//If the form is submitted
if(isset($_POST['submitted'])) {
//Check to see if the honeypot captcha field was filled in
if(trim($_POST['checking']) !== '') {
$captchaError = true;
} else {
//Check to make sure that the name field is not empty
if(trim($_POST['contactName']) === '') {
$nameError = 'You forgot to enter your name.';
$hasError = true;
} else {
$name = trim($_POST['contactName']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) === '') {
$emailError = 'You forgot to enter your email address.';
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$emailError = 'You entered an invalid email address.';
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//Check to make sure that the name field is not empty
if(trim($_POST['subject']) === '') {
$subjectError = 'You forgot to enter your subject.';
$hasError = true;
} else {
$subject = trim($_POST['subject']);
}
//Check to make sure comments were entered
if(trim($_POST['comments']) === '') {
$commentError = 'You forgot to enter your comments.';
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['comments']));
} else {
$comments = trim($_POST['comments']);
}
}
//If there is no error, send the email
if(!isset($hasError)) {
$info_email = get_option('CT_info_email');
$emailTo = $info_email;
$subject = $subject;
$sendCopy = trim($_POST['sendCopy']);
$body = "Name: $name \n\nEmail: $email \n\nComments: $comments";
$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
if($sendCopy == true) {
$subject = $subject;
$headers = 'From: Your Name <[email protected]>';
mail($email, $subject, $body, $headers);
}
$emailSent = true;
}
}
} ?>
--------------------------
contacto.js
--------------------------
Código:
function isEmailAddr(email) { var result = false; var theStr = new String(email); var index = theStr.indexOf("@"); if (index > 0) { var pindex = theStr.indexOf(".",index); if ((pindex > index+1) && (theStr.length > pindex+1)) result = true; } return result; } function validateFields() { var frmEl = document.getElementById('cForm'); var posName = document.getElementById('posName'); var posEmail = document.getElementById('posEmail'); var posRegard = document.getElementById('posRegard'); var posText = document.getElementById('posText'); var strCC = document.getElementById('selfCC'); var whiteSpace = /^[\s]+$/; if ( posText.value == '' || whiteSpace.test(posText.value) ) { alert("Por favor complete todos los campos."); } else if (posEmail.value.length<1){ alert("Por favor introduzca un email."); } else if (isEmailAddr(posEmail.value)==false){ alert("Por favor introduzca un email existente"); } else if ( posEmail.value == '' && strCC.checked == true ) { alert("Why are you trying to CC yourself without an email?"); alert("Just for that..."); alert("I\'m Clearing all the fields!"); frmEl.reset(); alert("There. Satisified."); alert("Now start over!"); posName.focus(); } else { sendPosEmail(); } } function sendPosEmail () { var success = document.getElementById('emailSuccess'); var posName = document.getElementById('posName'); var posEmail = document.getElementById('posEmail'); var posRegard = document.getElementById('posRegard'); var posText = document.getElementById('posText'); var strCC = document.getElementById('selfCC').value; var page = "scripts/xmlHttpRequest.php?contact=true&xml=true"; showContactTimer(); // quickly begin the load bar success.style.display = 'none'; // hide the success bar (incase this is a multi-email // convert (&, +, =) to string equivs. Needed so URL encoded POST won't choke. var str1 = posName.value; str1 = str1.replace(/&/g,"**am**"); str1 = str1.replace(/=/g,"**eq**"); str1 = str1.replace(/\+/g,"**pl**"); var str2 = posEmail.value; str2 = str2.replace(/&/g,"**am**"); str2 = str2.replace(/=/g,"**eq**"); str2 = str2.replace(/\+/g,"**pl**"); var str3 = posRegard.value; str3 = str3.replace(/&/g,"**am**"); str3 = str3.replace(/=/g,"**eq**"); str3 = str3.replace(/\+/g,"**pl**"); var str4 = posText.value; str4 = str4.replace(/&/g,"**am**"); str4 = str4.replace(/=/g,"**eq**"); str4 = str4.replace(/\+/g,"**pl**"); var stuff = "selfCC="+strCC+"&posName="+str1+"&posEmail="+str2+"&posRegard="+str3+"&posText="+str4; loadXMLPosDoc(page,stuff) } function showContactTimer () { var loader = document.getElementById('loadBar'); loader.style.display = 'block'; sentTimer = setTimeout("hideContactTimer()",6000); } function hideContactTimer () { var loader = document.getElementById('loadBar'); var success = document.getElementById('emailSuccess'); var fieldArea = document.getElementById('contactFormArea'); var inputs = fieldArea.getElementsByTagName('input'); var inputsLen = inputs.length; var tAreas = fieldArea.getElementsByTagName('textarea'); var tAreasLen = tAreas.length; // Hide the load bar alas! Done Loading loader.style.display = "none"; success.style.display = "block"; success.innerHTML = '<strong style="color:red;">'+grabPosXML("confirmation")+'</strong>'; // Now Hijack the form elements for ( i=0;i<inputsLen;i++ ) { if ( inputs[i].getAttribute('type') == 'text' ) { inputs[i].value = ''; } } for ( j=0;j<tAreasLen;j++ ) { tAreas[j].value = ''; } } function ajaxContact() { var frmEl = document.getElementById('cForm'); addEvent(frmEl, 'submit', validateFields, false); frmEl.onsubmit = function() { return false; } } addEvent(window, 'load',ajaxContact, false);