-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.php
59 lines (49 loc) · 1.76 KB
/
contact.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
<?php
require_once __DIR__."/lib/config.php";
require_once __DIR__ . "/lib/session.php";
require_once __DIR__ . "/lib/send_email.php";
require_once __DIR__."/templates/header.php";
?>
<?php
$messages = [];
$errors = [];
if (isset($_POST["sendContact"])) {
//@todo gérer l'envoi d'email avec affichage de message et erreurs si email non valide ou message vide
if (!empty($_POST['email'] && !empty($_POST['message']))) {
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
if (sendMail($_POST['email'], $_POST['message'])) {
$messages[] = "Email envoyé avec succès";
} else {
$errors[] = "Erreur lors de l'envoi du mail";
}
} else {
$errors[] = "Email invalide";
}
} else {
$errors[] = "Un des champs est vide";
}
}
?>
<h1>Contact</h1>
<?php foreach($messages as $message) { ?>
<div class="alert alert-success">
<?=$message; ?>
</div>
<?php } ?>
<?php foreach($errors as $error) { ?>
<div class="alert alert-success">
<?=$error; ?>
</div>
<?php } ?>
<form method="POST" enctype="multipart/form-data">
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="message" class="form-label">Message</label>
<textarea class="form-control" id="message" name="message" rows="3"></textarea>
</div>
<input type="submit" name="sendContact" class="btn btn-primary" value="Envoyer">
</form>
<?php require_once __DIR__."/templates/footer.php"; ?>