Just dont get it

Just dont get it

I have the following jquery contact form on my site.  As soon as I fill in the form and press submit the form disappears and I get thrown back to my home page.  I suspect it is the <div> at the beginning of the code that is throwing me back out.  Anyway, the mail never gets delivered.  

  1. <div class='mainbody'>

  2. <?php
  3. //If the form is submitted
  4. if(isset($_POST['submit'])) {

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

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

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

  25. //Check to make sure comments were entered
  26. if(trim($_POST['message']) == '') {
  27. $hasError = true;
  28. } else {
  29. if(function_exists('stripslashes')) {
  30. $comments = stripslashes(trim($_POST['message']));
  31. } else {
  32. $comments = trim($_POST['message']);
  33. }
  34. }

  35. //If there is no error, send the email
  36. if(!isset($hasError)) {
  37. $emailTo = 'austen.robinson@outlook.com'; //Put your own email address here
  38. $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
  39. $headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;

  40. mail($$email, $subject, $body, $headers);
  41. $emailSent = true;
  42. }
  43. }
  44. ?>
  45. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  46.         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  47. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

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

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

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

  59. <style type="text/css">
  60. body {
  61. font-family:Arial, Tahoma, sans-serif;
  62. }
  63. #contact-wrapper {
  64. width:430px;
  65. border:1px solid #e2e2e2;
  66. background:#f1f1f1;
  67. padding:20px;
  68. }
  69. #contact-wrapper div {
  70. clear:both;
  71. margin:1em 0;
  72. }
  73. #contact-wrapper label {
  74. display:block;
  75. float:none;
  76. font-size:16px;
  77. width:auto;
  78. }
  79. form#contactform input {
  80. border-color:#B7B7B7 #E8E8E8 #E8E8E8 #B7B7B7;
  81. border-style:solid;
  82. border-width:1px;
  83. padding:5px;
  84. font-size:16px;
  85. color:#333;
  86. }
  87. form#contactform textarea {
  88. font-family:Arial, Tahoma, Helvetica, sans-serif;
  89. font-size:100%;
  90. padding:0.6em 0.5em 0.7em;
  91. border-color:#B7B7B7 #E8E8E8 #E8E8E8 #B7B7B7;
  92. border-style:solid;
  93. border-width:1px;
  94. }
  95. </style>
  96. </head>

  97. <body>
  98. <div id="contact-wrapper">

  99. <?php if(isset($hasError)) { //If errors are found ?>
  100. <p class="error">Please check if you've filled all the fields with valid information. Thank you.</p>
  101. <?php } ?>

  102. <?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
  103. <p><strong>Email Successfully Sent!</strong></p>
  104. <p>Thank you <strong><?php echo $name;?></strong> for using my contact form! Your email was successfully sent and I will be in touch with you soon.</p>
  105. <?php } ?>

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

  111. <div>
  112. <label for="email"><strong>Email:</strong></label>
  113. <input type="text" size="50" name="email" id="email" value="" class="required email" />
  114. </div>

  115. <div>
  116. <label for="subject"><strong>Subject:</strong></label>
  117. <input type="text" size="50" name="subject" id="subject" value="" class="required" />
  118. </div>

  119. <div>
  120. <label for="message"><strong>Message:</strong></label>
  121. <textarea rows="5" cols="50" name="message" id="message" class="required"></textarea>
  122. </div>
  123.    <input type="submit" value="Send Message" name="submit" />
  124. </form>
  125. </div>
  126. </body>
  127. </html>


  128. </div>