From d04d01aecc681106bf993f1dbabe8511069f03e8 Mon Sep 17 00:00:00 2001 From: stiti Date: Sun, 26 May 2024 15:44:36 +0200 Subject: [PATCH] =?UTF-8?q?Commit=20de=20Louay=20:=20Corrections=20de=20bu?= =?UTF-8?q?g=20+=20Am=C3=A9lioration=20des=20mails?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/controllers/Contact.php | 136 +++++++++++- .../application/controllers/Search.php | 1 - .../application/controllers/Utilisateur.php | 201 ++++++++++++++++++ .../application/controllers/temporaire.php | 7 - CodeIgniter-3.1.13/assets/css/email.css | 37 ++++ 5 files changed, 370 insertions(+), 12 deletions(-) delete mode 100644 CodeIgniter-3.1.13/application/controllers/temporaire.php create mode 100644 CodeIgniter-3.1.13/assets/css/email.css diff --git a/CodeIgniter-3.1.13/application/controllers/Contact.php b/CodeIgniter-3.1.13/application/controllers/Contact.php index 067c575..32f66ff 100644 --- a/CodeIgniter-3.1.13/application/controllers/Contact.php +++ b/CodeIgniter-3.1.13/application/controllers/Contact.php @@ -13,7 +13,7 @@ class Contact extends CI_Controller { public function __construct() { parent::__construct(); - // Chargez le modèle si nécessaire + // Chargez le modèle si nécessaire (pour le moment pas encore besoin) } public function index() { @@ -22,6 +22,7 @@ class Contact extends CI_Controller { $this->load->view('layout/footer_dark'); } + // Permet d'envoyer un mail au Support de Onzeur quand le client écrit un mail depuis l'accueil public function send_message() { if ($this->input->post()) { $name = $this->input->post('name'); @@ -43,8 +44,71 @@ class Contact extends CI_Controller { $mail->isHTML(true); $mail->Subject = 'Formulaire de contact Onzeur - ' . $name; - $mail->Body = $message; - + $mail->Body = ' + + + + + + + + +
+
+ Logo Onzeur +
+
+

Nouveau message de contact

+

Nom: ' . $name . '

+

Email: ' . $email . '

+

Message:

+

' . nl2br($message) . '

+
+ +
+ + '; + $mail->send(); $this->load->view('layout/header_dark'); $this->load->view('confirmation_mail.php'); @@ -59,6 +123,7 @@ class Contact extends CI_Controller { } } + // Permet d'envoyer un mail au Support de Onzeur quand le client écrit un mail depuis la page de contacte (donc avec plus d'infos) public function send_detailed_message() { if ($this->input->post()) { $name = $this->input->post('name'); @@ -81,7 +146,70 @@ class Contact extends CI_Controller { $mail->isHTML(true); $mail->Subject = 'Formulaire de contact Onzeur - ' . $name; - $mail->Body = $message; + $mail->Body = ' + + + + + + + + +
+
+ Logo Onzeur +
+
+

Nouveau message de contact

+

Nom: ' . $name . '

+

Email: ' . $email . '

+

Message:

+

' . nl2br($message) . '

+
+ +
+ + '; // Gérer la pièce jointe if (!empty($attachment['tmp_name'])) { diff --git a/CodeIgniter-3.1.13/application/controllers/Search.php b/CodeIgniter-3.1.13/application/controllers/Search.php index dc097dc..884211e 100644 --- a/CodeIgniter-3.1.13/application/controllers/Search.php +++ b/CodeIgniter-3.1.13/application/controllers/Search.php @@ -13,7 +13,6 @@ class Search extends CI_Controller { public function index(){ // Récupérer la requête de recherche depuis la barre de recherche $query = $this->input->get('query'); - include 'temporaire.php'; // Vérifier que la requête de recherche n'est pas vide if (empty($query)) { diff --git a/CodeIgniter-3.1.13/application/controllers/Utilisateur.php b/CodeIgniter-3.1.13/application/controllers/Utilisateur.php index fcf4b3c..9af67c0 100644 --- a/CodeIgniter-3.1.13/application/controllers/Utilisateur.php +++ b/CodeIgniter-3.1.13/application/controllers/Utilisateur.php @@ -176,6 +176,18 @@ class Utilisateur extends CI_Controller { ); if ($this->Utilisateur_model->insert_avis($data)) { + // Envoyer un email en fonction de la note + $notation = intval($this->input->post('notation')); + if ($notation >= 1 && $notation <= 3) { + // Envoyer un email d'excuse + $user = $this->Utilisateur_model->get_user_by_id($this->session->userdata('user_id')); + $this->send_excuse_email($user->email, $user->prenom, $user->nom); + } elseif ($notation >= 4 && $notation <= 5) { + // Envoyer un email de remerciement + $user = $this->Utilisateur_model->get_user_by_id($this->session->userdata('user_id')); + $this->send_thank_you_email($user->email, $user->prenom, $user->nom); + } + $this->session->set_flashdata('success', 'Avis ajouté avec succès.'); } else { $this->session->set_flashdata('error', 'Une erreur est survenue. Veuillez réessayer.'); @@ -184,6 +196,195 @@ class Utilisateur extends CI_Controller { redirect('/'); } } + + + private function send_excuse_email($to_email, $prenom, $nom) { + $mail = new PHPMailer(true); + try { + // Configuration du serveur SMTP + $mail->isSMTP(); + $mail->Host = 'smtp.gmail.com'; + $mail->SMTPAuth = true; + $mail->Username = 'onzeur.contact@gmail.com'; + $mail->Password = 'ofoi hjpo isxf azdk'; + $mail->SMTPSecure = 'tls'; + $mail->Port = 587; + + // Destinataires + $mail->setFrom('onzeur.contact@gmail.com', 'Support Onzeur'); + $mail->addAddress($to_email); + + // Contenu de l'email + $mail->isHTML(true); + $mail->Subject = 'Retours sur votre mauvaise experience sur Onzeur.'; + + $mail_body = ' + + + + + + + + +
+
+ Logo Onzeur +
+
+

Désolé, '.$prenom.' '.$nom.' !

+

Nous sommes désolés de constater que votre expérience sur Onzeur n\'a pas été à la hauteur de vos attentes.

+

Nous prenons en compte vos retours et nous nous efforçons constamment d\'améliorer notre plateforme pour mieux vous servir.

+

Nous espérons avoir l\'occasion de vous satisfaire pleinement à l\'avenir.

+

Cordialement,
L\'équipe Onzeur

+
+ +
+ + '; + + $mail->Body = $mail_body; + + $mail->send(); + } catch (Exception $e) { + log_message('error', 'Erreur lors de l\'envoi de l\'email: ' . $mail->ErrorInfo); + } + } + + + private function send_thank_you_email($to_email, $prenom, $nom) { + $mail = new PHPMailer(true); + try { + // Configuration du serveur SMTP + $mail->isSMTP(); + $mail->Host = 'smtp.gmail.com'; + $mail->SMTPAuth = true; + $mail->Username = 'onzeur.contact@gmail.com'; + $mail->Password = 'ofoi hjpo isxf azdk'; + $mail->SMTPSecure = 'tls'; + $mail->Port = 587; + + // Destinataires + $mail->setFrom('onzeur.contact@gmail.com', 'Support Onzeur'); + $mail->addAddress($to_email); + + // Contenu de l'email + $mail->isHTML(true); + $mail->Subject = 'Merci de votre avis sur Onzeur !'; + + $mail_body = ' + + + + + + + + +
+
+ Logo Onzeur +
+
+

Merci, '.$prenom.' '.$nom.' !

+

Nous vous remercions d\'avoir pris le temps de laisser votre avis sur Onzeur. Votre contribution est très précieuse pour nous.

+

Nous prenons en compte vos retours et nous nous efforçons constamment d\'améliorer notre plateforme pour mieux vous servir.

+

N\'hésitez pas à continuer à partager vos impressions avec nous.

+

Cordialement,
L\'équipe Onzeur

+
+ +
+ + '; + + $mail->Body = $mail_body; + + $mail->send(); + } catch (Exception $e) { + log_message('error', 'Erreur lors de l\'envoi de l\'email: ' . $mail->ErrorInfo); + } + } + public function connexion(){ // Définir les règles de validation diff --git a/CodeIgniter-3.1.13/application/controllers/temporaire.php b/CodeIgniter-3.1.13/application/controllers/temporaire.php deleted file mode 100644 index 73c3e20..0000000 --- a/CodeIgniter-3.1.13/application/controllers/temporaire.php +++ /dev/null @@ -1,7 +0,0 @@ - \ No newline at end of file diff --git a/CodeIgniter-3.1.13/assets/css/email.css b/CodeIgniter-3.1.13/assets/css/email.css new file mode 100644 index 0000000..5a59875 --- /dev/null +++ b/CodeIgniter-3.1.13/assets/css/email.css @@ -0,0 +1,37 @@ +body { + font-family: Arial, sans-serif; + background-color: #f4f4f4; + margin: 0; + padding: 0; +} +.container { + width: 80%; + margin: 0 auto; + background-color: #fff; + padding: 20px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); +} +.header { + text-align: center; + padding: 20px; +} +.header img { + max-width: 150px; +} +.content { + margin-top: 20px; +} +.content h1 { + color: #333; +} +.content p { + font-size: 16px; + line-height: 1.6; + color: #666; +} +.footer { + margin-top: 20px; + text-align: center; + font-size: 14px; + color: #999; +} \ No newline at end of file