-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.php
More file actions
72 lines (60 loc) · 1.98 KB
/
action.php
File metadata and controls
72 lines (60 loc) · 1.98 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
68
69
70
71
72
<?php
$firstname_error = $lastname_error = $email_error = $countries_error = $city_error = '';
$firstname = $lastname = $email = $countries = $city = '';
$mail_sent = false;
$mail_error = false;
if (!empty($_POST)) {
function sanitize_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$has_errors = false;
if (empty($_POST['firstname'])) {
$firstname_error = 'Veuillez renseigner votre prénom';
$has_errors = true;
} else {
$firstname = sanitize_input($_POST['firstname']);
}
if (empty($_POST['lastname'])) {
$lastname_error = 'Veuillez renseigner votre nom';
$has_errors = true;
} else {
$lastname = sanitize_input($_POST['lastname']);
}
if (empty($_POST['email'])) {
$email_error = 'Veuillez renseigner votre e-mail';
$has_errors = true;
} else {
$email = sanitize_input($_POST['email']);
}
if (empty($_POST['city'])) {
$city_error = 'Veuillez renseigner votre ville';
$has_errors = true;
} else {
$city = sanitize_input($_POST['city']);
}
if (empty($_POST['countries'])) {
$countries_error = 'Veuillez choisir un pays parmi ceux proposés.';
$has_errors = true;
} else {
$countries = sanitize_input($_POST['countries']);
}
if (!$has_errors) {
$from = 'jadefrh@gmail.com';
$subject = 'Confirmation d\'envoi de formulaire';
$message = $firstname . ', merci de votre participation.';
// Headers
$headers = 'From: '.$firstname.' <'.$from.">\r\n";
$headers .= 'Reply-To: '.$email."\r\n";
$headers .= "MIME-Version: 1.O\r\n";
$headers .= 'Content-type: text/html; charset-utf-8';
// Send email
if (mail($email, $subject, $message, $headers)) {
$mail_sent = true;
} else {
$mail_error = true;
}
}
}