Skip to content

Instantly share code, notes, and snippets.

Created April 10, 2014 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/10411873 to your computer and use it in GitHub Desktop.
Save anonymous/10411873 to your computer and use it in GitHub Desktop.
<?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));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment