-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform_process.php
More file actions
67 lines (59 loc) · 1.94 KB
/
Copy pathform_process.php
File metadata and controls
67 lines (59 loc) · 1.94 KB
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
<?php
// define variables and set to empty values
$name_error = $email_error = $phone_error = "";
$naam = $email = $telefoon = $bericht = $success = "";
//form is submitted with POST method
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["naam"])) {
$name_error = "Naam is benodigd";
} else {
$naam = test_input($_POST["naam"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$naam)) {
$name_error = "Alleen letters en spaties toegestaan";
}
}
if (empty($_POST["email"])) {
$email_error = "Email is benodigd";
} else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$email_error = "Ongeldig email formaat";
}
}
if (empty($_POST["telefoon"])) {
$phone_error = "Telefoon is benodigd";
} else {
$telefoon = test_input($_POST["telefoon"]);
// check if e-mail address is well-formed
if (!preg_match("/^(\d[\s-]?)?[\(\[\s-]{0,2}?\d{3}[\)\]\s-]{0,2}?\d{3}[\s-]?\d{4}$/i",$telefoon)) {
$phone_error = "Ongeldig telefoonnummer";
}
}
if (empty($_POST["bericht"])) {
$message = "";
} else {
$message = test_input($_POST["bericht"]);
}
if ($name_error == '' and $email_error == '' and $phone_error == ''){
$message_body = '';
unset($_POST['submit']);
foreach ($_POST as $key => $value){
$message_body .= "$key: $value\n";
}
$to = 'casper.plate@hotmail.com';
$subject = 'Contactformulier claass';
$headers = "From: noreply@cloudbeheerder.it" . "\r\n";
if (mail($to, $subject, $bericht, $headers)){
$success = "Bericht verstuurd, bedankt voor het contacteren!";
$naam = $email = $telefoon = $bericht = '';
}
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}