Guest User

Untitled

a guest
Nov 22nd, 2017
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. <?php
  2.  
  3. if(isset($_POST['email'])) {
  4.  
  5.  
  6.  
  7. // EDIT THE 2 LINES BELOW AS REQUIRED
  8.  
  9. $email_to = $_POST['email'];
  10.  
  11. $email_subject = "Letter to Santa";
  12.  
  13.  
  14.  
  15.  
  16.  
  17. function died($error) {
  18.  
  19. // your error code can go here
  20.  
  21. echo "We are very sorry, but there were error(s) found with the form you submitted. ";
  22.  
  23. echo "These errors appear below.<br /><br />";
  24.  
  25. echo $error."<br /><br />";
  26.  
  27. echo "Please go back and fix these errors.<br /><br />";
  28.  
  29. die();
  30.  
  31. }
  32.  
  33.  
  34.  
  35. // validation expected data exists
  36.  
  37. if(!isset($_POST['name']) ||
  38.  
  39. !isset($_POST['email']) ||
  40.  
  41. !isset($_POST['message'])) {
  42.  
  43. died('We are sorry, but there appears to be a problem with the form you submitted.');
  44.  
  45. }
  46.  
  47.  
  48.  
  49. $first_name = $_POST['name']; // required
  50.  
  51. $email_from = $_POST['email']; // required
  52.  
  53. $message = $_POST['message']; // required
  54.  
  55.  
  56.  
  57. $error_message = "";
  58.  
  59. $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  60.  
  61. if(!preg_match($email_exp,$email_from)) {
  62.  
  63. $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  64.  
  65. }
  66.  
  67. $string_exp = "/^[A-Za-z .'-]+$/";
  68.  
  69. if(!preg_match($string_exp,$first_name)) {
  70.  
  71. $error_message .= 'The Name you entered does not appear to be valid.<br />';
  72.  
  73. }
  74.  
  75. if(strlen($message) < 2) {
  76.  
  77. $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  78.  
  79. }
  80.  
  81. if(strlen($error_message) > 0) {
  82.  
  83. died($error_message);
  84.  
  85. }
  86.  
  87.  
  88.  
  89.  
  90. function clean_string($string) {
  91.  
  92. $bad = array("content-type","bcc:","to:","cc:","href");
  93.  
  94. return str_replace($bad,"",$string);
  95.  
  96. }
  97.  
  98.  
  99.  
  100. $email_message .= "From: ".clean_string($first_name)."\n";
  101.  
  102. $email_message .= "Dear Santa, ".clean_string($message)."\n";
  103.  
  104.  
  105.  
  106.  
  107.  
  108. // create email headers
  109.  
  110. $headers = 'From: '.$email_from."\r\n".
  111.  
  112. 'Reply-To: '.$email_from."\r\n" .
  113.  
  114. 'X-Mailer: PHP/' . phpversion();
  115.  
  116. @mail($email_to, $email_subject, $email_message, $headers);
  117.  
  118. ?>
  119.  
  120.  
  121.  
  122. <!-- include your own success html here -->
  123.  
  124. <html>
  125. <head>
  126. <meta charset="utf-8">
  127. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  128. <title>Dear Santa,</title>
  129. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
  130. <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Molle:400i">
  131. <link rel="stylesheet" href="assets/css/styles.css">
  132. </head>
  133. <body>
  134. <div class="container" style="text-align:center;">
  135. <div class="row">
  136. <div class="col-md-12 col-lg-10 offset-lg-1">
  137. <h1 style="color:rgb(255,255,255);margin:1em 0px 0px 0px;font-family:Molle, cursive;font-size:60px;">Your letter is on it's way to Santa, remember to be Nice and stay off that Naughty List!</h1>
  138. <a style="margin-bottom: 1em;" href="index.html">Back to Dear Santa</a>
  139. </br>
  140. </div>
  141. </div>
  142. </div>
  143. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  144. <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
  145. </body>
  146. </html>
  147.  
  148.  
  149. <?php
  150.  
  151. }
  152.  
  153. ?>
Advertisement
Add Comment
Please, Sign In to add comment