Guest User

Untitled

a guest
May 24th, 2018
901
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. <?php
  2. if(isset($_POST['email'])) {
  3.  
  4.  
  5. $email_to = "alexhughes92@hotmail.co.uk";
  6.  
  7. $email_subject = "North Somerset Rentals";
  8.  
  9.  
  10. function died($error) {
  11. // your error code can go here
  12. echo "We're sorry, but there's errors found with the form you submitted.<br /><br />";
  13. echo $error."<br /><br />";
  14. echo "Please go back and fix these errors.<br /><br />";
  15. die();
  16. }
  17.  
  18.  
  19. if(!isset($_POST['first_name']) ||
  20. !isset($_POST['last_name']) ||
  21. !isset($_POST['email']) ||
  22. !isset($_POST['telephone']) ||
  23. !isset($_POST['comments'])) {
  24. died('We are sorry, but there appears to be a problem with the form you submitted.');
  25. }
  26.  
  27. $first_name = $_POST['first_name']; // required
  28. $last_name = $_POST['last_name']; // required
  29. $email_from = $_POST['email']; // required
  30. $telephone = $_POST['telephone']; // not required
  31. $comments = $_POST['comments']; // required
  32.  
  33. $error_message = "";
  34. $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  35. if(!preg_match($email_exp,$email_from)) {
  36. $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  37. }
  38. $string_exp = "/^[A-Za-z .'-]+$/";
  39. if(!preg_match($string_exp,$first_name)) {
  40. $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  41. }
  42. if(!preg_match($string_exp,$last_name)) {
  43. $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  44. }
  45. if(strlen($comments) < 2) {
  46. $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  47. }
  48. if(strlen($error_message) > 0) {
  49. died($error_message);
  50. }
  51. $email_message = "Form details below.\n\n";
  52.  
  53. function clean_string($string) {
  54. $bad = array("content-type","bcc:","to:","cc:","href");
  55. return str_replace($bad,"",$string);
  56. }
  57.  
  58. $email_message .= "First Name: ".clean_string($first_name)."\n";
  59. $email_message .= "Last Name: ".clean_string($last_name)."\n";
  60. $email_message .= "Email: ".clean_string($email_from)."\n";
  61. $email_message .= "Telephone: ".clean_string($telephone)."\n";
  62. $email_message .= "Comments: ".clean_string($comments)."\n";
  63.  
  64.  
  65. // create email headers
  66. $headers = 'From: '.$email_from."\r\n".
  67. 'Reply-To: '.$email_from."\r\n" .
  68. 'X-Mailer: PHP/' . phpversion();
  69. @mail($email_to, $email_subject, $email_message, $headers);
  70. ?>
  71.  
  72.  
  73. Thank you for contacting us. We will be in touch with you very soon.
  74.  
  75. <?php
  76. }
  77. die();
  78. ?>
Add Comment
Please, Sign In to add comment