-
Notifications
You must be signed in to change notification settings - Fork 0
/
send-form.php
79 lines (67 loc) · 1.99 KB
/
send-form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
//error_reporting(E_ALL);
define('RETURN_OK', '/form_ok');
define('RETURN_FAIL', '/form_fail');
// We use form field names of the form fx, where x is a number. This way, spammers can not know which to fill an which to leave out.
$forms = array(
"beitritt" => array(
"fields" => array(
2 => "Name",
4 => "Geburtsdatum",
6 => "Adresse",
8 => "Telefon",
10 => "E-Mail",
12 => "E-Mail (Wiederholung)"
),
"notallowed" => array(1, 3, 5, 7, 9, 11),
"required" => array(2, 4, 6, 8, 10, 12),
"receiver" => '[email protected]',
"subject" => 'Beitrittsantrag'
),
"kontakt" => array(
"fields" => array(
2 => "Name",
4 => "Nachricht",
6 => "Kontakt (Telefon/E-Mail)"
),
"notallowed" => array(1, 3, 5),
"required" => array(2, 4),
"receiver" => '[email protected]',
"subject" => 'Kontaktanfrage'
)
);
if (empty($_POST['form_id'])) {
header('Location: '.RETURN_FAIL);
exit();
}
$id = $_POST['form_id'];
if (! isset($forms[$id])) {
header('Location: '.RETURN_FAIL);
exit();
}
foreach ($forms[$id]['notallowed'] as $na) {
if (! empty($_POST["f$na"])) {
header('Location: '.RETURN_FAIL);
exit();
}
}
foreach ($forms[$id]['required'] as $req) {
if (empty($_POST["f$req"])) {
header('Location: '.RETURN_FAIL);
exit();
}
}
$text = "Folgende Informationen wurden im Formular eingegeben:\n";
foreach ($forms[$id]['fields'] as $n => $label) {
$content = empty($_POST["f$n"]) ? ' - keine Eingabe - ' : $_POST["f$n"];
$text .= "\n{$label}: {$content}";
}
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=utf-8";
$success = mail($forms[$id]['receiver'], $forms[$id]['subject'], $text, implode("\r\n",$headers));
if ($success) {
header('Location: '.RETURN_OK);
exit();
}
header('Location: '.RETURN_FAIL);