Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.55 KB | None | 0 0
  1. <?php define('STRIP_QUOTES', (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())); ?>
  2. <h2>Kontakt</h2>
  3.  
  4. <?php if(contact_is_sent()): ?>
  5. <p>Vielen Dank,</p>
  6. <p>Ihre Nachricht wurde erfolgreich übermittelt und wird so schnell wie möglich bearbeitet!</p>
  7. <?php else: ?>
  8. <form action="kontakt.html" method="post">
  9. <?php if(contact_has_error()): ?>
  10. <div class="errors">
  11. <?php foreach(contact_get_errors() as $error): ?>
  12. <p><?php print $error; ?></p>
  13. <?php endforeach; ?>
  14. </div>
  15. <?php endif; ?>
  16.  
  17. <table class="contact-table">
  18. <tbody>
  19. <tr>
  20. <th><label for="c-type">Anrede:</label></th>
  21. <td>
  22. <select name="type" id="c-type" size="1">
  23. <option value="0">- Bitte wählen -</option>
  24. <option value="1" <?php contact_reselect('type', '1'); ?>>Herr</option>
  25. <option value="2" <?php contact_reselect('type', '2'); ?>>Frau</option>
  26. </select>
  27. </td>
  28. </tr>
  29. <tr>
  30. <th><label for="c-name">Ihr Name:</label></th>
  31. <td><input type="text" name="name" class="text" id="c-name" size="45" <?php contact_refill('name'); ?> /></td>
  32. </tr>
  33. <tr>
  34. <th><label for="c-email">Ihre E-Mail:</label></th>
  35. <td><input type="text" name="email" class="text" id="c-email" size="45" <?php contact_refill('email'); ?> /></td>
  36. </tr>
  37. <tr>
  38. <th><label for="c-subject">Betreff:</label></th>
  39. <td><input type="text" name="subject" class="text" id="c-subject" size="45" <?php contact_refill('subject'); ?> /></td>
  40. </tr>
  41. <tr>
  42. <td colspan="2">
  43. <p><strong><label for="c-message">Ihre Nachricht:</label></strong></p>
  44. <p><textarea name="message" id="c-message" rows="5" cols="1"><?php contact_refill('message', false); ?></textarea></p>
  45. </td>
  46. </tr>
  47. <tr>
  48. <td colspan="2" class="control">
  49. <p class="left">
  50. <input type="checkbox" name="copy" id="c-copy" value="1" />
  51. <label for="c-copy">Kopie an meine E-Mail senden</label>
  52. </p>
  53. <p>
  54. <input type="reset" onclick="return confirm('Wirklich alle Felder leeren?');" value="Zurücksetzen" />
  55. <input type="submit" value="Senden" />
  56. </p>
  57. </td>
  58. </tr>
  59. </tbody>
  60. </table>
  61. </form>
  62. <?php endif;
  63.  
  64.  
  65. // ----------------------------------------
  66.  
  67. function contact_reselect($name, $value) {
  68. if(!empty($_POST[$name]) && $_POST[$name] === $value)
  69. print 'selected="selected"';
  70. }
  71.  
  72. function contact_refill($name, $wrap_value = true) {
  73. if(!empty($_POST[$name])) {
  74. $value = $_POST[$name];
  75.  
  76. if(STRIP_QUOTES)
  77. $value = stripslashes($value);
  78.  
  79. $tpl = '%s';
  80. if($wrap_value === true)
  81. $tpl = 'value="%s"';
  82.  
  83. printf($tpl, htmlentities($value, ENT_COMPAT, 'UTF-8'));
  84. }
  85. }
  86.  
  87. function contact_get_errors() {
  88. global $contact_errors;
  89.  
  90. return empty($contact_errors) ? array() : $contact_errors;
  91. }
  92.  
  93. function contact_has_error() {
  94. global $contact_errors;
  95.  
  96. return !empty($contact_errors);
  97. }
  98.  
  99. function contact_is_sent() {
  100. if(!empty($_POST))
  101. // form prüfen
  102. return contact_validate();
  103.  
  104. // form wurde nicht gesendet oder es gab fehler
  105. return false;
  106. }
  107.  
  108. function contact_validate() {
  109. global $contact_errors;
  110.  
  111. $fields = array(
  112. 'type' => array('Anrede', true),
  113. 'name' => array('Name', true),
  114. 'email' => array('E-Mail', true),
  115. 'subject' => array('Betreff', true),
  116. 'message' => array('Nachricht', true),
  117. 'copy' => array('', false, 0));
  118.  
  119. foreach($fields as $name => $info) {
  120. if(empty($_POST[$name])) {
  121. if($info[1] === true) {
  122. $contact_errors[] = sprintf('Bitte das Feld "%s" ausf&uuml;llen', $info[0]);
  123. continue;
  124. }
  125.  
  126. $$name = $info[2];
  127. }
  128.  
  129. $$name = $_POST[$name];
  130. }
  131.  
  132. if(!empty($contact_errors))
  133. return false;
  134.  
  135. // email prüfen
  136. if(!preg_match('/^[^@]+@(?:[^\.]+\.)*[^\.]+\..+$/', $email)) {
  137. $contact_errors[] = 'Die angegebene E-Mail ist nicht korrekt';
  138. return false;
  139. }
  140.  
  141. // anrede
  142. $type = (((int) $type) === 1) ? 'Herr' : 'Frau';
  143.  
  144. $mail = base64_encode(sprintf("Nachricht von: %s\nAm: %s Uhr\n\n%s",
  145. $name, date('d.m.Y, H:i'), $message));
  146.  
  147. $header = "from: <contactform@domain.tld> Kontaktforumlar Unda\r\n";
  148. $header .= "Transfer-Encoding: base64";
  149.  
  150. // -- hier email angeben --
  151. mail('info@toyota-bs.de', $subject, $mail, $header);
  152.  
  153. if(((bool) $copy) === true)
  154. mail($email, 'Kopie Ihrer Nachricht an Unda', $mail, $header);
  155.  
  156. return true;
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement