Jump to content

ayuda con formulario contacto plis :D


Recommended Posts

hola a todos bueno les comento compre un template en monster y no tengo mucho conocimiento en php y solo modificar las plantillas y todo eso y me surgio un problema en el formulario cuando trato de enviar no me llega a mi correo. y modifique donde salia [email protected] y no me funciona. dejo los codigos para que me echen una manito

 

Formulario.html

 

<div class="padding-left1">
					 <h3>FORMULARIO</h3>
						<div id="contact_form">
	 <form id="contact-form" method="post" class="main-contacts">
	  <fieldset>
	   <input type="hidden" name="owner_email" id="owner_email" value="[email protected]" />
	   <input type="hidden" name="serverProcessorType" id="serverProcessorType" value="asp" />
	   <input type="hidden" name="smtpMailServer" id="smtpMailServer" value="localhost" />
	   <input type="hidden" name="stripHTML" id="stripHTML" value="true" />[/color][/font]
[font="helvetica, arial, sans-serif"][color="#282828"]
	   <div class="rowElem">
		<label><span class="text-form">Nombre:</span><input type="text" name="name" id="name"/></label>
		<label class="error" for="name" id="name_error">*Este campo es obligatorio.</label>
		<label class="error" for="name" id="name_error2">*No es un nombre válido.</label>
	   </div>
	   <div class="rowElem">
		<label><span class="text-form">E-mail:</span><input type="text" name="email" id="email"/></label>
		<label class="error" for="email" id="email_error">*Este campo es obligatorio.</label>[/color][/font]
[font="helvetica, arial, sans-serif"][color="#282828"]			<label class="error" for="email" id="email_error2">*Ingrese un correo electronico valido.</label>
	   </div>
	   <div class="rowElem">
		<label><span class="text-form">Teléfono:</span>
		  <input type="text" name="phone" id="phone"/></label>
		<label class="error" for="phone" id="phone_error">*Este campo es obligatorio.</label>
		<label class="error" for="phone" id="phone_error2">*Esto no es un numero de telefono valido.</label>
	   </div>[/color][/font]
[font="helvetica, arial, sans-serif"][color="#282828"]		   <div class="textarea-box">
		<div class="wrapper label-2"><div class="text-form">Mensaje:</div><textarea name="message" id="message"></textarea></div>
		<label class="error" for="message" id="message_error">*Este campo es obligatorio.</label>
		<label class="error" for="message" id="message_error2">*El mensaje es demasiado corto.</label>
	   </div>
	   <div class="buttons">
		<a class="link-1"  id="clear">Borrar</a><a name="submit" class="link-1" id="submit">Enviar</a>
	   </div>
	  </fieldset>
	 </form>
	</div>
					</div>

 

MailHandler.php

 

<?php
$owner_email = $_POST["owner_email"];
$headers = 'From:' . $_POST["email"];
$subject = 'A message from your site visitor ' . $_POST["name"];
$messageBody = "";

$messageBody .= '<p>Visitor: ' . $_POST["name"] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
$messageBody .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
$messageBody .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
$messageBody .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";

if($_POST["stripHTML"] == 'true'){
 $messageBody = strip_tags($messageBody);
}[/color][/font]
[font=helvetica, arial, sans-serif][color=#282828]try{
 if(!mail($owner_email, $subject, $messageBody, $headers)){
  throw new Exception('correo electrónico no enviado');
 }else{
  echo 'correo electrónico enviado';
 }
}catch(Exception $e){
 echo $e->getMessage() ."\n";
}
?>

 

MailHandler.ashx

 

<%@ WebHandler Language="C#" Class="Handler" Debug="true" %>
using System;
using System.Web;
using System.Net.Mail;
using System.Text.RegularExpressions;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
 SmtpClient mailClient = new SmtpClient(context.Request.Form.Get("smtpMailServer"));
 string owner_email = context.Request.Form.Get("[email protected]");
 string subject = "A message from your site visitor " + context.Request.Form.Get("name");
 string email = context.Request.Form.Get("email");
 string messageBody = "";

 messageBody += "<p>Visitor: " + context.Request.Form.Get("name") + "</p>\n";
 messageBody += "<br>\n";
 messageBody += "<p>Email Address: " + context.Request.Form.Get("email") + "</p>\n";
 messageBody += "<br>\n";
 messageBody += "<p>Phone Number: " + context.Request.Form.Get("phone") + "</p>\n";
 messageBody += "<br>\n";
 messageBody += "<p>Message: " + context.Request.Form.Get("message") + "</p>\n";


 MailMessage message = new MailMessage();

 try{
  message.From = new MailAddress(email.ToString());
 }catch (FormatException e) {
  context.Response.Write(e.Message);
 }

 message.To.Add(owner_email);
 message.Subject = subject;
 if(context.Request.Form.Get("stripHTML") == "true"){
  message.IsBodyHtml = false;
	    messageBody = Regex.Replace(messageBody, "<.*?>", string.Empty);
 }else{
 message.IsBodyHtml = true;
 }
 message.Body = messageBody;

 try{
  mailClient.Send(message);
 }catch (SmtpException e) {
  context.Response.Write("mail failed");
 }
 context.Response.Write("mail sent");
}
public bool IsReusable {
 get {
  return false;
 }
}
}

 

 

 

contact-form.js

 

 

$(function(){
$('.error').fadeOut(0);

// reset form and hide all errors
$("a#clear").click(function(){
 $('.error').fadeOut(0);
 $('form#contact-form').clearForm();
});

// show message error if after editing
// the name field contains improper value
$("input#name").blur(function(){
 if(validateInput('name')){
  if(!validateName()){
   $("label#name_error").fadeOut(0);
   $("label#name_error2").fadeIn(250);
  }
 }else{
  $("label#name_error2").fadeOut(0);
 }
});

// show message error if after editing
// the email field contains improper value
$("input#email").blur(function(){
 if(validateInput('email')){
  if(!validateEmail()){
   $("label#email_error").fadeOut(0);
   $("label#email_error2").fadeIn(250);
  }
 }else{
  $("label#email_error2").fadeOut(0);
 }
});

// show message error if after editing
// the phone field contains improper value
$("input#phone").blur(function(){
 if(validateInput('phone')){
  if(!validatePhone()){
   $("label#phone_error").fadeOut(0);
   $("label#phone_error2").fadeIn(250);
  }
 }else{
  $("label#phone_error2").fadeOut(0);
 }
});

// show message error if after editing
// the message field contains improper value
$("textarea#message").blur(function(){
 if(validateTextArea('message')){
  if(!validateMessage()){
   $("label#message_error").fadeOut(0);
   $("label#message_error2").fadeIn(250);
  }
 }else{
  $("label#message_error2").fadeOut(0);
 }
});

$("input#name").keydown(function(){
 if(validateInput('name')){
  $("label#name_error").fadeOut(0);
 }
 if(validateName()){
  $("label#name_error2").fadeOut(0);
 }
});

$("input#email").keydown(function(){
 if(validateInput('email')){
  $("label#email_error").fadeOut(0);
 }
 if(validateEmail()){
  $("label#email_error2").fadeOut(0);
 }
});

$("input#phone").keydown(function(){
 if(validateInput('phone')){
  $("label#phone_error").fadeOut(0);
 }
 if(validatePhone()){
  $("label#phone_error2").fadeOut(0);
 }
});

$("textarea#message").keydown(function(){
 if(validateTextArea('message')){
  $("label#message_error").fadeOut(0);
 }
 if(validateMessage()){
  $("label#message_error2").fadeOut(0);
 }
});

var owner_email = $("input#owner_email").val();
if(!isValidEmailAddress(owner_email)){
 $('#contact_form').html("<label class='error'>*Owner email is not valid</label>")
}

$("a#submit").click(function(){
 // validate and process form
 var quit = false;
 if(validateName()){
  name = validateName();
  $("label#name_error").fadeOut(0);
  $("label#name_error2").fadeOut(0);
 }else if(validateInput('name')){
  $("label#name_error").fadeOut(0);
  $("label#name_error2").fadeIn(250);
  quit = true;
 }else{
  $("label#name_error").fadeIn(250);
  $("label#name_error2").fadeOut(0);
  quit = true;
 }
 if(validateEmail()){
  email = validateEmail();
  $("label#email_error").fadeOut(0);
  $("label#email_error2").fadeOut(0);
 }else if(validateInput('email')){
  $("label#email_error").fadeOut(0);
  $("label#email_error2").fadeIn(250);
  quit = true;
 }else{
  $("label#email_error").fadeIn(250);
  $("label#email_error2").fadeOut(0);
  quit = true;
 }
 if(validatePhone()){
  phone = validatePhone();
  $("label#phone_error").fadeOut(0);
  $("label#phone_error2").fadeOut(0);
 }else if(validateInput('phone')){
  $("label#phone_error").fadeOut(0);
  $("label#phone_error2").fadeIn(250);
  quit = true;
 }else{
  $("label#phone_error").fadeIn(250);
  $("label#phone_error2").fadeOut(0);
  quit = true;
 }
 if(validateMessage()){
  message = validateMessage();
  $("label#message_error").fadeOut(0);
  $("label#message_error2").fadeOut(0);
 }else if(validateTextArea('message')){
  $("label#message_error").fadeOut(0);
  $("label#message_error2").fadeIn(250);
  quit = true;
 }else{
  $("label#message_error").fadeIn(250);
  $("label#message_error2").fadeOut(0);
  quit = true;
 }
 if(quit){
  return false;
 }

 var stripHTML = $("input#stripHTML").val();
 var smtpMailServer = $("input#smtpMailServer").val();

 var dataString = 'name=' + name + '&email=' + email + '&phone=' + phone + '&message=' + message + '&owner_email=' + owner_email + '&stripHTML=' + stripHTML + '&smtpMailServer=' + smtpMailServer;

 var serverProcessorType = $("input#serverProcessorType").val();
 if(serverProcessorType == 'asp'){
  fileExtension = 'ashx';
 }else{
  fileExtension = serverProcessorType;
 }
 var mailHandlerURL = "mail/MailHandler." + fileExtension;
 $.ajax({
  type: "POST",
  url: mailHandlerURL,
  data: dataString,
  success: function(){
   $('.error').fadeOut(0);
   $('form#contact-form').clearForm();
   $('#contact_form').html("<div>Contact form submitted!</div>").append("<br><label for='message'><strong style='background:none;'>We will be in touch soon.</strong></label>").fadeOut(0).fadeIn(1500, function(){
 $('#contact_form').append("<br><br><a id='back' onclick='window.location.reload(); return false;' class='link-1'>back</a>");
   });
  }
 });   
 return false;
});
});
$.fn.clearForm = function(){
return this.each(function(){
 var type = this.type, tag = this.tagName.toLowerCase();
 if (tag == 'form'){
  return $(':input',this).clearForm();
 }
 if (type == 'text' || type == 'password' || tag == 'textarea'){
  this.value = '';
 }else if (type == 'checkbox' || type == 'radio'){
  this.checked = false;
 }else if (tag == 'select'){
  this.selectedIndex = -1;
 }
});
};
function isValidName(name){
var pattern = new RegExp(/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/);

return pattern.test(name);
}
function isValidEmailAddress(emailAddress){
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);

return pattern.test(emailAddress);
}
function isValidPhoneNumber(phoneNumber){
var pattern = new RegExp(/^\+?(\d[\d\-\+\(\) ]{5,}\d$)/);

return pattern.test(phoneNumber);
}
function validateName(){
var name = $("input#name").val();
if(isValidName(name)){
 return name;
}else{
 return false;
}
}
function validateEmail(){
var email = $("input#email").val();
if(!isValidEmailAddress(email)){
 return false;
}else{
 return email;
}
}
function validatePhone(){
var phone = $("input#phone").val();
if(!isValidPhoneNumber(phone)){
 return false;
}else{
 return phone;
}
}
function validateMessage(){
var message = $("textarea#message").val();
if(message.length <= 19){
 return false;
}else{
 return message;
}
}
// make sure visitor does not input a blank field
function validateInput(field){
var fieldObject = $("input#" + field + "").val();
if(fieldObject.length < 1){
 return false;
}else{
 return true;
}
}
function validateTextArea(field){
var fieldObject = $("textarea#" + field + "").val();
if(fieldObject.length < 1){
 return false;
}else{
 return true;
}
}

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...