Guest User

Untitled

a guest
Dec 30th, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. <?php
  2.  
  3. $contactnameErr = $emailErr = $phoneErr = $subjectErr = $messageErr = "";
  4. $contactname = $email = $phone = $subject = $message = "";
  5.  
  6. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  7.  
  8. $contactsend= 1;
  9.  
  10. if (empty($_POST["contactname"])) {
  11. $contactnameErr = "* Name is required";
  12. $contactsend= 0;
  13. } else {
  14. $contactname = test_input($_POST["contactname"]);
  15. // check if name only contains letters and whitespace
  16. if (!preg_match("/^[a-zA-Z ]*$/",$contactname)) {
  17. $contactnameErr = "* Only letters and white space allowed";
  18. $contactsend= 0;
  19. }
  20. }
  21.  
  22. if (empty($_POST["contactemail"])) {
  23. $contactemailErr = "* Email is required";
  24. $contactsend= 0;
  25. } else {
  26. $contactemail = test_input($_POST["contactemail"]);
  27. // check if e-mail address is well-formed
  28. if (!filter_var($contactemail, FILTER_VALIDATE_EMAIL)) {
  29. $contactemailErr = "* Invalid email format";
  30. $contactsend= 0;
  31. }
  32. }
  33.  
  34.  
  35.  
  36. if (empty($_POST["contactphone"])) {
  37. $contactphoneErr = "* Phone is required";
  38. $contactsend= 0;
  39. } else {
  40. $contactphone = test_input($_POST["contactphone"]);
  41. $contactsend= 0;
  42. }
  43.  
  44.  
  45.  
  46. if (empty($_POST["contactsubject"])) {
  47. $contactsubjectErr = "* Subject is required";
  48. $contactsend= 0;
  49. } else {
  50. $contactsubject = test_input($_POST["contactsubject"]);
  51. $contactsend= 0;
  52. }
  53.  
  54.  
  55. if (empty($_POST["contactmessage"])) {
  56. $contactmessageErr = "* Message is required";
  57. $contactsend= 0;
  58. } else {
  59. $contactmessage = test_input($_POST["contactmessage"]);
  60. $contactsend= 0;
  61. }
  62.  
  63. echo $contactsend;
  64.  
  65. if($contactsend== 1)
  66. {
  67. //send mail
  68. $message = "nSpecial Events , Contact Us . nName : " . $contactname . "nEmail : " . $contactemail . "nPhone : " . $contactphone
  69. . "nSubject : " . $contactsubject ."nMessage : " . $contactmessage;
  70. require("/home/specialeventsleb/public_html/phpmailer/PHPMailer/class.phpmailer.php");
  71. $mail = new PHPMailer(true);
  72. $mail->isSMTP();
  73. $mail->Host = 'smtp.office365.com';
  74. $mail->Port = 587;
  75. $mail->SMTPSecure = 'tls';
  76. $mail->SMTPAuth = true;
  77. $mail->Username = 'email1';
  78. $mail->Password = 'password1';
  79. $mail->SetFrom('email1', 'FromEmail');
  80. $mail->addAddress('email1', 'ToEmail');
  81. $mail->AddAddress('email2', 'ToEmail1');
  82. $mail->AddAddress('email3', 'ToEmail2');
  83. $mail->SMTPDebug = true;
  84. $mail->Timeout = 2000;
  85. $mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
  86. $mail->Debugoutput = 'echo';
  87. $mail->Subject = 'Message from Special Events Website';
  88. $mail->Body = $message;
  89. $mail->send();
  90. }
  91.  
  92. }
  93.  
  94. function test_input($data) {
  95. $data = trim($data);
  96. $data = stripslashes($data);
  97. $data = htmlspecialchars($data);
  98. return $data;
  99. }
  100.  
  101. ?>
  102.  
  103.  
  104. <div id="ContactUs">
  105. <!--<img class="ComputerBanner" src="Pictures/map/ContactUsBanner.png" />-->
  106. <img class="MobileBanner" src="Pictures/map/ContactUsBannerMobile.png" />
  107. <div class="ContactBox">
  108. <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
  109. <h2>SEND US A MESSAGE!</h2>
  110. <span>We'd be happy to hear from you.</span>
  111. <input name="contactname" placeholder="Name" type="text" value="<?php echo $contactname;?>"/> <span class="error"> <?php echo $contactnameErr;?></span>
  112. <input name="contactemail" placeholder="Email" type="text" value="<?php echo $contactemail;?>" /><span class="error"> <?php echo $contactemailErr;?></span>
  113. <input name="contactphone" placeholder="Phone #" type="text" value="<?php echo $contactphone;?>" /><span class="error"> <?php echo $contactphoneErr;?></span>
  114. <input name="contactsubject" placeholder="Subject" type="text" value="<?php echo $contactsubject;?>" /><span class="error"> <?php echo $contactsubjectErr;?></span>
  115. <textarea name="contactmessage" placeholder="Message"><?php echo $contactmessage;?></textarea><span class="error"> <?php echo $contactmessageErr;?></span>
  116. <input type="submit" name="submit" value="Send" class="contact-button" />
  117. </form>
  118. </div>
  119. </div>
Add Comment
Please, Sign In to add comment