Skip to content

Instantly share code, notes, and snippets.

Created April 10, 2014 18:56

Revisions

  1. @invalid-email-address Anonymous created this gist Apr 10, 2014.
    48 changes: 48 additions & 0 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    <?php
    header('Content-type: text/plain; charset=UTF-8');

    $config = array(
    'emails' => ['ener@mailinator.com'],
    'subject' => "Nowe zgloszenie Energia",
    'fields' => array (
    'name' => array ('label' => 'Imię i nazwisko'),
    'email' => array ('label' => 'Adres e-mail'),
    'phone' => array ('label' => 'Telefon'),
    'street' => array ('label' => 'Ulica'),
    'city' => array ('label' => 'Miasto'),
    'message' => array ('label' => 'Wiadomość', 'newline' => true),
    ),
    );

    $message = 'Nowe zgłoszenie' . "\n\n";
    $valid = true;
    $mq = get_magic_quotes_gpc();
    foreach ($config['fields'] as $key => $field) {
    if (empty($_POST[$key])) {
    $valid = false;
    break;
    }

    $value = $_POST[$key];
    if ($mq) {
    $value = stripslashes($value);
    }

    $newline = isset($field['newline']) ? "\n" : "";

    $message .= sprintf("%s: %s%s\n", $field['label'], $newline, $value);
    }

    if ($valid) {
    foreach ($config['emails'] as $recipient) {
    mail($recipient, $config['subject'], $message, 'Content-type: text/plain; charset=UTF-8');
    }
    }

    $target = isset($_POST['target']) ? $_POST['target'] : null;
    $target = ($mq && $target) ? stripslashes($target) : $target;

    if ($target) {
    header('Location: ' . $target . ((false === strpos($target, '?'))?'?':'&') . 'success=' . ((int)$valid));
    }
    ?>