Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php define('STRIP_QUOTES', (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())); ?>
- <h2>Kontakt</h2>
- <?php if(contact_is_sent()): ?>
- <p>Vielen Dank,</p>
- <p>Ihre Nachricht wurde erfolgreich übermittelt und wird so schnell wie möglich bearbeitet!</p>
- <?php else: ?>
- <form action="kontakt.html" method="post">
- <?php if(contact_has_error()): ?>
- <div class="errors">
- <?php foreach(contact_get_errors() as $error): ?>
- <p><?php print $error; ?></p>
- <?php endforeach; ?>
- </div>
- <?php endif; ?>
- <table class="contact-table">
- <tbody>
- <tr>
- <th><label for="c-type">Anrede:</label></th>
- <td>
- <select name="type" id="c-type" size="1">
- <option value="0">- Bitte wählen -</option>
- <option value="1" <?php contact_reselect('type', '1'); ?>>Herr</option>
- <option value="2" <?php contact_reselect('type', '2'); ?>>Frau</option>
- </select>
- </td>
- </tr>
- <tr>
- <th><label for="c-name">Ihr Name:</label></th>
- <td><input type="text" name="name" class="text" id="c-name" size="45" <?php contact_refill('name'); ?> /></td>
- </tr>
- <tr>
- <th><label for="c-email">Ihre E-Mail:</label></th>
- <td><input type="text" name="email" class="text" id="c-email" size="45" <?php contact_refill('email'); ?> /></td>
- </tr>
- <tr>
- <th><label for="c-subject">Betreff:</label></th>
- <td><input type="text" name="subject" class="text" id="c-subject" size="45" <?php contact_refill('subject'); ?> /></td>
- </tr>
- <tr>
- <td colspan="2">
- <p><strong><label for="c-message">Ihre Nachricht:</label></strong></p>
- <p><textarea name="message" id="c-message" rows="5" cols="1"><?php contact_refill('message', false); ?></textarea></p>
- </td>
- </tr>
- <tr>
- <td colspan="2" class="control">
- <p class="left">
- <input type="checkbox" name="copy" id="c-copy" value="1" />
- <label for="c-copy">Kopie an meine E-Mail senden</label>
- </p>
- <p>
- <input type="reset" onclick="return confirm('Wirklich alle Felder leeren?');" value="Zurücksetzen" />
- <input type="submit" value="Senden" />
- </p>
- </td>
- </tr>
- </tbody>
- </table>
- </form>
- <?php endif;
- // ----------------------------------------
- function contact_reselect($name, $value) {
- if(!empty($_POST[$name]) && $_POST[$name] === $value)
- print 'selected="selected"';
- }
- function contact_refill($name, $wrap_value = true) {
- if(!empty($_POST[$name])) {
- $value = $_POST[$name];
- if(STRIP_QUOTES)
- $value = stripslashes($value);
- $tpl = '%s';
- if($wrap_value === true)
- $tpl = 'value="%s"';
- printf($tpl, htmlentities($value, ENT_COMPAT, 'UTF-8'));
- }
- }
- function contact_get_errors() {
- global $contact_errors;
- return empty($contact_errors) ? array() : $contact_errors;
- }
- function contact_has_error() {
- global $contact_errors;
- return !empty($contact_errors);
- }
- function contact_is_sent() {
- if(!empty($_POST))
- // form prüfen
- return contact_validate();
- // form wurde nicht gesendet oder es gab fehler
- return false;
- }
- function contact_validate() {
- global $contact_errors;
- $fields = array(
- 'type' => array('Anrede', true),
- 'name' => array('Name', true),
- 'email' => array('E-Mail', true),
- 'subject' => array('Betreff', true),
- 'message' => array('Nachricht', true),
- 'copy' => array('', false, 0));
- foreach($fields as $name => $info) {
- if(empty($_POST[$name])) {
- if($info[1] === true) {
- $contact_errors[] = sprintf('Bitte das Feld "%s" ausfüllen', $info[0]);
- continue;
- }
- $$name = $info[2];
- }
- $$name = $_POST[$name];
- }
- if(!empty($contact_errors))
- return false;
- // email prüfen
- if(!preg_match('/^[^@]+@(?:[^\.]+\.)*[^\.]+\..+$/', $email)) {
- $contact_errors[] = 'Die angegebene E-Mail ist nicht korrekt';
- return false;
- }
- // anrede
- $type = (((int) $type) === 1) ? 'Herr' : 'Frau';
- $mail = base64_encode(sprintf("Nachricht von: %s\nAm: %s Uhr\n\n%s",
- $name, date('d.m.Y, H:i'), $message));
- $header = "from: <contactform@domain.tld> Kontaktforumlar Unda\r\n";
- $header .= "Transfer-Encoding: base64";
- // -- hier email angeben --
- mail('info@toyota-bs.de', $subject, $mail, $header);
- if(((bool) $copy) === true)
- mail($email, 'Kopie Ihrer Nachricht an Unda', $mail, $header);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement