From fb03d5b83243956f90f679deb8b0df4310f07531 Mon Sep 17 00:00:00 2001 From: stiti Date: Sat, 25 May 2024 18:03:24 +0200 Subject: [PATCH] Commit de Marco : Correction de bug PHPMailer --- .../application/controllers/Contact.php | 58 +++++++++++-- .../application/views/accueil.php | 2 +- .../application/views/confirmation_mail.php | 7 +- .../application/views/erreur_mail.php | 2 +- .../application/views/layout/footer_dark.php | 2 +- .../application/views/nous-contacter.php | 83 +++++++++++++++++++ 6 files changed, 143 insertions(+), 11 deletions(-) create mode 100644 CodeIgniter-3.1.13/application/views/nous-contacter.php diff --git a/CodeIgniter-3.1.13/application/controllers/Contact.php b/CodeIgniter-3.1.13/application/controllers/Contact.php index 707038d..067c575 100644 --- a/CodeIgniter-3.1.13/application/controllers/Contact.php +++ b/CodeIgniter-3.1.13/application/controllers/Contact.php @@ -17,17 +17,19 @@ class Contact extends CI_Controller { } public function index() { - // Vérifiez si le formulaire de contact a été soumis + $this->load->view('layout/header_dark'); + $this->load->view('nous-contacter'); + $this->load->view('layout/footer_dark'); + } + + public function send_message() { if ($this->input->post()) { - // Récupérez les données du formulaire $name = $this->input->post('name'); $email = $this->input->post('email'); $message = $this->input->post('message'); - // Envoi d'email avec PHPMailer $mail = new PHPMailer(true); try { - //Server settings $mail->isSMTP(); $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; @@ -53,9 +55,51 @@ class Contact extends CI_Controller { $this->load->view('layout/footer_dark'); } } else { - $this->load->view('layout/header_dark'); - $this->load->view('accueil'); - $this->load->view('layout/footer_dark'); + redirect('contact'); } } + + public function send_detailed_message() { + if ($this->input->post()) { + $name = $this->input->post('name'); + $email = $this->input->post('email'); + $message = $this->input->post('message'); + $attachment = $_FILES['attachment']; + + $mail = new PHPMailer(true); + try { + $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; + + $mail->setFrom($email, $name); + $mail->addAddress('onzeur.contact@gmail.com'); + + $mail->isHTML(true); + $mail->Subject = 'Formulaire de contact Onzeur - ' . $name; + $mail->Body = $message; + + // Gérer la pièce jointe + if (!empty($attachment['tmp_name'])) { + $mail->addAttachment($attachment['tmp_name'], $attachment['name']); + } + + $mail->send(); + $this->load->view('layout/header_dark'); + $this->load->view('confirmation_mail.php'); + $this->load->view('layout/footer_dark'); + } catch (Exception $e) { + $this->load->view('layout/header_dark'); + $this->load->view('erreur_mail.php'); + $this->load->view('layout/footer_dark'); + } + } else { + redirect('nous-contacter'); + } + } } + diff --git a/CodeIgniter-3.1.13/application/views/accueil.php b/CodeIgniter-3.1.13/application/views/accueil.php index abc7708..bab810b 100644 --- a/CodeIgniter-3.1.13/application/views/accueil.php +++ b/CodeIgniter-3.1.13/application/views/accueil.php @@ -88,7 +88,7 @@

Contactez-nous

-
+ diff --git a/CodeIgniter-3.1.13/application/views/confirmation_mail.php b/CodeIgniter-3.1.13/application/views/confirmation_mail.php index 663b6d1..695af23 100644 --- a/CodeIgniter-3.1.13/application/views/confirmation_mail.php +++ b/CodeIgniter-3.1.13/application/views/confirmation_mail.php @@ -16,7 +16,12 @@

Nom:

Email:

Message:

- + + +

Fichier attaché:

+ + +
diff --git a/CodeIgniter-3.1.13/application/views/erreur_mail.php b/CodeIgniter-3.1.13/application/views/erreur_mail.php index 83e0191..7bc9b6b 100644 --- a/CodeIgniter-3.1.13/application/views/erreur_mail.php +++ b/CodeIgniter-3.1.13/application/views/erreur_mail.php @@ -14,7 +14,7 @@

Votre message n'a pas pu être envoyé.

Veuillez réessayer ultérieurement ou nous contacter directement à l'adresse suivante : onzeur.contact@gmail.com

- +
diff --git a/CodeIgniter-3.1.13/application/views/layout/footer_dark.php b/CodeIgniter-3.1.13/application/views/layout/footer_dark.php index 9e40874..6ce42c1 100644 --- a/CodeIgniter-3.1.13/application/views/layout/footer_dark.php +++ b/CodeIgniter-3.1.13/application/views/layout/footer_dark.php @@ -11,7 +11,7 @@ | © 2024 Onzeur | - Nous contacter + Nous contacter diff --git a/CodeIgniter-3.1.13/application/views/nous-contacter.php b/CodeIgniter-3.1.13/application/views/nous-contacter.php new file mode 100644 index 0000000..0c57119 --- /dev/null +++ b/CodeIgniter-3.1.13/application/views/nous-contacter.php @@ -0,0 +1,83 @@ + + + + + Nous contacter - Onzeur + + +
+

Nous contacter

+

N'hésitez pas à nous contacter pour toute question ou demande.

+
+ +
+
+

Formulaire de contact

+ +
+
+
+
+ + +
+
+ +