diff options
Diffstat (limited to 'src/controller/ContactFormController.php')
-rw-r--r-- | src/controller/ContactFormController.php | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/controller/ContactFormController.php b/src/controller/ContactFormController.php index 9d62a77..dcea868 100644 --- a/src/controller/ContactFormController.php +++ b/src/controller/ContactFormController.php | |||
@@ -27,17 +27,53 @@ class ContactFormController | |||
27 | } | 27 | } |
28 | die; | 28 | die; |
29 | } | 29 | } |
30 | static public function sendVisitorEmail(EntityManager $entityManager, array $json): void | ||
31 | { | ||
32 | $form = new FormValidation($json, 'email'); | ||
33 | |||
34 | $error = ''; | ||
35 | if($form->validate()){ | ||
36 | // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur | ||
37 | $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); | ||
38 | if($form_data === null){ | ||
39 | http_response_code(500); | ||
40 | echo json_encode(['success' => false, 'error' => 'server_error']); | ||
41 | die; | ||
42 | } | ||
43 | $recipient = $form_data->getData()['email'] ?? Config::$email_dest; | ||
44 | |||
45 | if(!EmailService::send($entityManager, $recipient, true, $form->getField('name'), $form->getField('email'), $form->getField('message'))){ | ||
46 | $error = 'email_not_sent'; | ||
47 | } | ||
48 | } | ||
49 | else{ | ||
50 | $error = $form->getErrors()[0]; // la 1ère erreur sera affichée | ||
51 | } | ||
52 | |||
53 | if(empty($error)){ | ||
54 | echo json_encode(['success' => true]); | ||
55 | } | ||
56 | else{ | ||
57 | echo json_encode(['success' => false, 'error' => $error]); | ||
58 | } | ||
59 | die; | ||
60 | } | ||
30 | static public function sendTestEmail(EntityManager $entityManager, array $json): void | 61 | static public function sendTestEmail(EntityManager $entityManager, array $json): void |
31 | { | 62 | { |
32 | // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur | 63 | // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur |
33 | $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); | 64 | $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); |
65 | if($form_data === null){ | ||
66 | http_response_code(500); | ||
67 | echo json_encode(['success' => false, 'error' => 'server_error']); | ||
68 | die; | ||
69 | } | ||
34 | $recipient = $form_data->getData()['email'] ?? Config::$email_dest; | 70 | $recipient = $form_data->getData()['email'] ?? Config::$email_dest; |
35 | 71 | ||
36 | if(EmailController::send($recipient, false, 'nom du visiteur', 'adresse@du_visiteur.fr', "TEST d'un envoi d'e-mail depuis le site web")){ | 72 | if(EmailService::send($entityManager, $recipient, false, 'nom du visiteur', 'adresse@du_visiteur.fr', "TEST d'un envoi d'e-mail depuis le site web")){ |
37 | echo json_encode(['success' => true]); | 73 | echo json_encode(['success' => true]); |
38 | } | 74 | } |
39 | else{ | 75 | else{ |
40 | echo json_encode(['success' => false]); | 76 | echo json_encode(['success' => false, 'error' => 'email_not_sent']); |
41 | } | 77 | } |
42 | die; | 78 | die; |
43 | } | 79 | } |