1. <?php session_start(); ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  6. <title>Untitled Document</title>
  7. </head>
  8.  
  9. <body>
  10. <div id="container">
  11.  
  12. <div id="wrapper">
  13. <div id="main-content">
  14. <?php
  15. if(isset($_POST['submit'])) {
  16.  
  17. $to = "somebody@calvarybucyrus.org";
  18.  
  19. $subject = $_POST['subject'];
  20. $name= $_POST['name'];
  21. $email = $_POST['email'];
  22. $message = $_POST['message'];
  23.  
  24. $number= $_POST['number']; //security
  25.  
  26. $body = "$message";
  27. $continue = "/";
  28. // email validation
  29. $error_msg='';
  30.  
  31. if(trim($name)=='') {$error_msg.="Please enter your Name and/or Surname !<br>";}
  32. if(trim($subject)=='') {$error_msg.="Please enter a subject title !<br>";}
  33.  
  34. if(trim($email)=='') {$error_msg.="Please enter an email!<br>";}
  35. else {
  36. // check if email is a valid address in this format username@domain.com
  37. if(!ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]", $email))
  38. {$error_msg.="Please enter a valid email address<br>";}
  39. }
  40.  
  41. if(trim($number)==''){$error_msg.="Please enter a (Valid) Security Code !<br>";}
  42. else {// check if numbers matches each other
  43. $session_num = (int) $_SESSION['number'];
  44. $post_num = (int) $_POST['number'];
  45. if (!($session_num == $post_num)) $error_msg.="Wrong value entered!<br>";
  46. }
  47.  
  48. // display error message if any, if not, proceed to other processing
  49. if(strlen($error_msg) < 1) {
  50. if(mail($to, $subject, $body)) {
  51. echo "Thanks <b>$name</b>, <br>Your message has been submitted to <br><b>$to</b></br>!</br>"; //display the message to say that your message was sent to....
  52. echo '<br><a href="' . $continue . '">Click here to continue.</a>';
  53. }
  54. else {
  55. echo "<font color=red>please try again later</font>";//there was an error with the mail function - please try again later
  56. }
  57. }
  58. else {echo "<font color=red>$error_msg</font>";}
  59.  
  60. }
  61.  
  62. //mail($to, $subject, $body);
  63. ?>
  64.  
  65. </div>
  66.  
  67. </div>
  68.  
  69.  
  70. </div>
  71.  
  72. <div>
  73. <PRE>
  74. <?php
  75. // For diagnostics
  76.  
  77. //echo "POST<HR>";
  78. //print_r($_POST);
  79. //echo "SESSION<HR>";
  80. //print_r($_SESSION);
  81. //echo "<HR>";
  82. ?>
  83. </PRE>
  84. </DIV>
  85.  
  86. </body>
  87. </html>