Contact Form Not Working Properly

  • amiecutietoes
  • Newbie
  • Newbie
  • User avatar
  • Posts: 10
  • Loc: Los Angeles, CA

Post 3+ Months Ago

So I have built a contact form out of AS2 and PHP. PHP 5 is enabled on my server, so that's not a problem. I think there is a slight error within my code somewhere. What happens is once online, you fill out the form and hit post, it goes to the "error sending email!". Below is my code so you can take a look at it and help me out. Thanks

<3 Amie

Code: [ Select ]
//
// SET FOCUS FIELDS
//
name_txt.onSetFocus = function() {
  name_mc.gotoAndPlay("write");
  name_title.gotoAndPlay("_white");
  if (this.text == "Name is Required!") {
    this.text = "";
  }
};
phone_txt.onSetFocus = function() {
  phone_mc.gotoAndPlay("write");
  phone_title.gotoAndPlay("_white");
  if (this.text == "Phone Number is Required!") {
    this.text = "";
  }
};
email_txt.onSetFocus = function() {
  email_mc.gotoAndPlay("write");
  email_title.gotoAndPlay("_white");
  if (this.text == "Email is Required!") {
    this.text = "";
  }
};
message_txt.onSetFocus = function() {
  message_mc.gotoAndPlay("write");
  message_title.gotoAndPlay("_white");
  if (this.text == "Message is Required!") {
    this.text = "";
  }
};


//
// KILL FOCUS FIELDS
//
name_txt.onKillFocus = function() {
  name_mc.gotoAndPlay("killFocus");
  name_title.gotoAndPlay("_glowing");
};
phone_txt.onKillFocus = function() {
  phone_mc.gotoAndPlay("killFocus");
  phone_title.gotoAndPlay("_glowing");
};
email_txt.onKillFocus = function() {
  email_mc.gotoAndPlay("killFocus");
  email_title.gotoAndPlay("_glowing");
};
message_txt.onKillFocus = function() {
  message_mc.gotoAndPlay("killFocus");
  message_title.gotoAndPlay("_glowing");
};


//TABS
name_txt.tabIndex = 0;
phone_txt.tabIndex = 1;
email_txt.tabIndex = 2;
message_txt.tabIndex = 3;
send_mc.tabIndex = 4;


//SEND ACTIONS/////////////////////////////////////
///////////////////////////////////////////////////


//ASTERICKS TO MARK WHAT NEEDS TO BE CORRECTED
nameBlank_mc._visible = false;
phoneBlank_mc._visible = false;
emailBlank_mc._visible = false;
messageBlank_mc._visible = false;


//LOADVARS
var senderLoad:LoadVars = new LoadVars();
var receiveLoad:LoadVars = new LoadVars();


//SEND ON RELEASE FUNCTION
send_mc.onRelease = function():Void {
  send_mc.gotoAndPlay("_release");
  outfxSound.start ();
  //HIDE ASTERICKS IN BEGINNING
  nameBlank_mc._visible = false;
  phoneBlank_mc._visible = false;
  emailBlank_mc._visible = false;
  messageBlank_mc._visible = false;
  //LOAD TEXT FOR SENDERLOAD
  senderLoad.name_txt = name_txt.text;
  senderLoad.phone_txt = phone_txt.text;
  senderLoad.email_txt = email_txt.text;
  senderLoad.message_txt = message_txt.text;
  //IF ANY TEXT FIELD IS BLANK OF INCORRECT, RETURN A FALSE
  if (name_txt.text == "" or name_txt.text == "Name is Required!") {
    name_txt.text = "Name is Required!";
    nameBlank_mc._visible = true;
  } else if (phone_txt.text == ""or phone_txt.text == "Phone Number is Required!") {
    phone_txt.text = "Phone Number is Required!";
    phoneBlank_mc._visible = true;
  } else if (email_txt.text == "" or name_txt.text == "Email is Required!") {
    email_txt.text = "Email is Required!";
    emailBlank_mc._visible = true;
  //IF EMAIL IS INVALID RETURN A FALSE (CODE FOR EMAIL
  //EMAIL VALIDATION IS LOCATED BELOW
  } else if (email_txt.text.emailValidation() == false) {
    email_txt.text = "Email is Invalid!";
    emailBlank_mc._visible = true;
  } else if (message_txt.text == ""or message_txt.text == "Message is Required!") {
    message_txt.text = "Message is Required!";
    messageBlank_mc._visible = true;
  } else {
    //IF ALL TEXT FIELDS ARE VALID, THEN SEND AND LOAD CONTACT.PHP
    senderLoad.sendAndLoad("contact.php", receiveLoad, "GET");
  }
};

//FUNCTION TO CHECK IF FORM IS SENT
receiveLoad.onLoad = function():Void {
  if (this.sentOk) {
    name_txt.text = "";
    phone_txt.text = "";
    email_txt.text = "";
    message_txt.text = "";
    status_txt.text = "Email Sent. Thanks!";
  } else {
    status_txt.text = "Error Sending Email!";
  }
};


//EMAIL VALIDATION
String.prototype.emailValidation = function() {
  //check to see if atleast 5 characters
  if (this.length < 5) {
    return false;
  }
  //Check to see if there are illegal characters within the email
  invalidChars = "`!#$%^&*()[]{}|:;'\",<>";
  for (i=0; i<this.length; i++) {
    if (invalidChars.indexOf(this.charAt(i)) != -1) {
      return false;
    }
  }
  //Check to see if the symbol @ is present, and
  //if its in a valid postition
  at = this.lastIndexOf("@");
  if (at<1 || (at == this.length-1)) {
    return false;
  }
  //Check to see if a period is present and if
  //its in a valid position
  period = this.lastIndexOf(".");
  if (period<4 || (period == this.length-1)) {
    return false;
  }
  //Check to see if the @ symbol and period are
  //within their valid positions.
  if (1>=period-at) {
    return false;
  }
  //Check to see if there are no two periods or
  //@ symbols in a row
  for (i=0; i<this.length; i++) {
    if ((this.charAt(i) == "." || this.charAt(i) == "@") && this.charAt(i) == this.charAt(i-1)) {
      return false;
    }
  }
  return true;  
}



//SEND BUTTON
this.send_mc.onRollOver = function() {
  send_mc.gotoAndPlay("_over");
  overfxSound.start ();
}

this.send_mc.onRollOut = function() {
  send_mc.gotoAndPlay("_out");
}

send_mc.tabEnabled=false;
  1. //
  2. // SET FOCUS FIELDS
  3. //
  4. name_txt.onSetFocus = function() {
  5.   name_mc.gotoAndPlay("write");
  6.   name_title.gotoAndPlay("_white");
  7.   if (this.text == "Name is Required!") {
  8.     this.text = "";
  9.   }
  10. };
  11. phone_txt.onSetFocus = function() {
  12.   phone_mc.gotoAndPlay("write");
  13.   phone_title.gotoAndPlay("_white");
  14.   if (this.text == "Phone Number is Required!") {
  15.     this.text = "";
  16.   }
  17. };
  18. email_txt.onSetFocus = function() {
  19.   email_mc.gotoAndPlay("write");
  20.   email_title.gotoAndPlay("_white");
  21.   if (this.text == "Email is Required!") {
  22.     this.text = "";
  23.   }
  24. };
  25. message_txt.onSetFocus = function() {
  26.   message_mc.gotoAndPlay("write");
  27.   message_title.gotoAndPlay("_white");
  28.   if (this.text == "Message is Required!") {
  29.     this.text = "";
  30.   }
  31. };
  32. //
  33. // KILL FOCUS FIELDS
  34. //
  35. name_txt.onKillFocus = function() {
  36.   name_mc.gotoAndPlay("killFocus");
  37.   name_title.gotoAndPlay("_glowing");
  38. };
  39. phone_txt.onKillFocus = function() {
  40.   phone_mc.gotoAndPlay("killFocus");
  41.   phone_title.gotoAndPlay("_glowing");
  42. };
  43. email_txt.onKillFocus = function() {
  44.   email_mc.gotoAndPlay("killFocus");
  45.   email_title.gotoAndPlay("_glowing");
  46. };
  47. message_txt.onKillFocus = function() {
  48.   message_mc.gotoAndPlay("killFocus");
  49.   message_title.gotoAndPlay("_glowing");
  50. };
  51. //TABS
  52. name_txt.tabIndex = 0;
  53. phone_txt.tabIndex = 1;
  54. email_txt.tabIndex = 2;
  55. message_txt.tabIndex = 3;
  56. send_mc.tabIndex = 4;
  57. //SEND ACTIONS/////////////////////////////////////
  58. ///////////////////////////////////////////////////
  59. //ASTERICKS TO MARK WHAT NEEDS TO BE CORRECTED
  60. nameBlank_mc._visible = false;
  61. phoneBlank_mc._visible = false;
  62. emailBlank_mc._visible = false;
  63. messageBlank_mc._visible = false;
  64. //LOADVARS
  65. var senderLoad:LoadVars = new LoadVars();
  66. var receiveLoad:LoadVars = new LoadVars();
  67. //SEND ON RELEASE FUNCTION
  68. send_mc.onRelease = function():Void {
  69.   send_mc.gotoAndPlay("_release");
  70.   outfxSound.start ();
  71.   //HIDE ASTERICKS IN BEGINNING
  72.   nameBlank_mc._visible = false;
  73.   phoneBlank_mc._visible = false;
  74.   emailBlank_mc._visible = false;
  75.   messageBlank_mc._visible = false;
  76.   //LOAD TEXT FOR SENDERLOAD
  77.   senderLoad.name_txt = name_txt.text;
  78.   senderLoad.phone_txt = phone_txt.text;
  79.   senderLoad.email_txt = email_txt.text;
  80.   senderLoad.message_txt = message_txt.text;
  81.   //IF ANY TEXT FIELD IS BLANK OF INCORRECT, RETURN A FALSE
  82.   if (name_txt.text == "" or name_txt.text == "Name is Required!") {
  83.     name_txt.text = "Name is Required!";
  84.     nameBlank_mc._visible = true;
  85.   } else if (phone_txt.text == ""or phone_txt.text == "Phone Number is Required!") {
  86.     phone_txt.text = "Phone Number is Required!";
  87.     phoneBlank_mc._visible = true;
  88.   } else if (email_txt.text == "" or name_txt.text == "Email is Required!") {
  89.     email_txt.text = "Email is Required!";
  90.     emailBlank_mc._visible = true;
  91.   //IF EMAIL IS INVALID RETURN A FALSE (CODE FOR EMAIL
  92.   //EMAIL VALIDATION IS LOCATED BELOW
  93.   } else if (email_txt.text.emailValidation() == false) {
  94.     email_txt.text = "Email is Invalid!";
  95.     emailBlank_mc._visible = true;
  96.   } else if (message_txt.text == ""or message_txt.text == "Message is Required!") {
  97.     message_txt.text = "Message is Required!";
  98.     messageBlank_mc._visible = true;
  99.   } else {
  100.     //IF ALL TEXT FIELDS ARE VALID, THEN SEND AND LOAD CONTACT.PHP
  101.     senderLoad.sendAndLoad("contact.php", receiveLoad, "GET");
  102.   }
  103. };
  104. //FUNCTION TO CHECK IF FORM IS SENT
  105. receiveLoad.onLoad = function():Void {
  106.   if (this.sentOk) {
  107.     name_txt.text = "";
  108.     phone_txt.text = "";
  109.     email_txt.text = "";
  110.     message_txt.text = "";
  111.     status_txt.text = "Email Sent. Thanks!";
  112.   } else {
  113.     status_txt.text = "Error Sending Email!";
  114.   }
  115. };
  116. //EMAIL VALIDATION
  117. String.prototype.emailValidation = function() {
  118.   //check to see if atleast 5 characters
  119.   if (this.length < 5) {
  120.     return false;
  121.   }
  122.   //Check to see if there are illegal characters within the email
  123.   invalidChars = "`!#$%^&*()[]{}|:;'\",<>";
  124.   for (i=0; i<this.length; i++) {
  125.     if (invalidChars.indexOf(this.charAt(i)) != -1) {
  126.       return false;
  127.     }
  128.   }
  129.   //Check to see if the symbol @ is present, and
  130.   //if its in a valid postition
  131.   at = this.lastIndexOf("@");
  132.   if (at<1 || (at == this.length-1)) {
  133.     return false;
  134.   }
  135.   //Check to see if a period is present and if
  136.   //its in a valid position
  137.   period = this.lastIndexOf(".");
  138.   if (period<4 || (period == this.length-1)) {
  139.     return false;
  140.   }
  141.   //Check to see if the @ symbol and period are
  142.   //within their valid positions.
  143.   if (1>=period-at) {
  144.     return false;
  145.   }
  146.   //Check to see if there are no two periods or
  147.   //@ symbols in a row
  148.   for (i=0; i<this.length; i++) {
  149.     if ((this.charAt(i) == "." || this.charAt(i) == "@") && this.charAt(i) == this.charAt(i-1)) {
  150.       return false;
  151.     }
  152.   }
  153.   return true;  
  154. }
  155. //SEND BUTTON
  156. this.send_mc.onRollOver = function() {
  157.   send_mc.gotoAndPlay("_over");
  158.   overfxSound.start ();
  159. }
  160. this.send_mc.onRollOut = function() {
  161.   send_mc.gotoAndPlay("_out");
  162. }
  163. send_mc.tabEnabled=false;


PHP Code: [ Select ]
<?PHP
$sendTo = "myemailaddress";
$subject = "Website Contact";
 
$contact_name = $_GET['name_txt'];
$contact_phone = $_GET['phone_txt'];
$contact_email = $_GET['email_txt'];
$contact_message = $_GET['message_txt'];
 
$message = "
Name: $contact_name \n
Email: $contact_email \n
Phone: $contact_phone \n\n
Message: $contact_message";
 
$headers = "From: $contact_name: $contact_email";
$headers .= "\nReply-To: $contact_email";
 
mail($sendTo, $subject, $message, $headers);
echo "sentOk=" . $sentOk;
?>
  1. <?PHP
  2. $sendTo = "myemailaddress";
  3. $subject = "Website Contact";
  4.  
  5. $contact_name = $_GET['name_txt'];
  6. $contact_phone = $_GET['phone_txt'];
  7. $contact_email = $_GET['email_txt'];
  8. $contact_message = $_GET['message_txt'];
  9.  
  10. $message = "
  11. Name: $contact_name \n
  12. Email: $contact_email \n
  13. Phone: $contact_phone \n\n
  14. Message: $contact_message";
  15.  
  16. $headers = "From: $contact_name: $contact_email";
  17. $headers .= "\nReply-To: $contact_email";
  18.  
  19. mail($sendTo, $subject, $message, $headers);
  20. echo "sentOk=" . $sentOk;
  21. ?>

I have added "myemailaddress" above for security purposes.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

Does it work if you remove all the validation?
  • amiecutietoes
  • Newbie
  • Newbie
  • User avatar
  • Posts: 10
  • Loc: Los Angeles, CA

Post 3+ Months Ago

nope, still not sending :(
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 475

Post 3+ Months Ago

So you are not getting an email at all? I also noticed that in the PHP code you never set the $sentOk variable or did this get left out by mistake? .... Are you doing this on a testing environment or on a web server. (My home testing server has PHP5 enabled but email functionality disabled)
  • amiecutietoes
  • Newbie
  • Newbie
  • User avatar
  • Posts: 10
  • Loc: Los Angeles, CA

Post 3+ Months Ago

I think I got it. I changed $_GET to $_POST. Then My variables were wrong.

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 9 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.