Advertisement
Guest User

Untitled

a guest
Mar 1st, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 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 = "coiurile@gmail.com";
  10.  
  11. $email_subject = "Contact form";
  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. $comments = $_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.  
  68. if(strlen($error_message) > 0) {
  69.  
  70. died($error_message);
  71.  
  72. }
  73.  
  74. $email_message = "Form details below.\n\n";
  75.  
  76.  
  77.  
  78. function clean_string($string) {
  79.  
  80. $bad = array("content-type","bcc:","to:","cc:","href");
  81.  
  82. return str_replace($bad,"",$string);
  83.  
  84. }
  85.  
  86.  
  87.  
  88. $email_message .= "Name: ".clean_string($name)."\n";
  89.  
  90. $email_message .= "Email: ".clean_string($email_from)."\n";
  91.  
  92. $email_message .= "Message: ".clean_string($Message)."\n";
  93.  
  94.  
  95.  
  96.  
  97.  
  98. // create email headers
  99.  
  100. $headers = 'From: '.$email_from."\r\n".
  101.  
  102. 'Reply-To: '.$email_from."\r\n" .
  103.  
  104. 'X-Mailer: PHP/' . phpversion();
  105.  
  106. @mail($email_to, $email_subject, $email_message, $headers);
  107.  
  108. ?>
  109.  
  110.  
  111.  
  112. <!-- include your own success html here -->
  113.  
  114.  
  115.  
  116. Thank you for contacting us. We will be in touch with you very soon.
  117.  
  118.  
  119.  
  120. <?php
  121.  
  122. }
  123.  
  124. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement