Commit de Marco : Correction de bug PHPMailer

This commit is contained in:
stiti 2024-05-25 18:03:24 +02:00
parent dd7f100b30
commit fb03d5b832
6 changed files with 143 additions and 11 deletions

View File

@ -17,17 +17,19 @@ class Contact extends CI_Controller {
} }
public function index() { 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()) { if ($this->input->post()) {
// Récupérez les données du formulaire
$name = $this->input->post('name'); $name = $this->input->post('name');
$email = $this->input->post('email'); $email = $this->input->post('email');
$message = $this->input->post('message'); $message = $this->input->post('message');
// Envoi d'email avec PHPMailer
$mail = new PHPMailer(true); $mail = new PHPMailer(true);
try { try {
//Server settings
$mail->isSMTP(); $mail->isSMTP();
$mail->Host = 'smtp.gmail.com'; $mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true; $mail->SMTPAuth = true;
@ -53,9 +55,51 @@ class Contact extends CI_Controller {
$this->load->view('layout/footer_dark'); $this->load->view('layout/footer_dark');
} }
} else { } else {
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('layout/header_dark');
$this->load->view('accueil'); $this->load->view('confirmation_mail.php');
$this->load->view('layout/footer_dark'); $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');
} }
} }
} }

View File

@ -88,7 +88,7 @@
<div class="contact"> <div class="contact">
<h2>Contactez-nous</h2> <h2>Contactez-nous</h2>
<form action="<?php echo site_url('contact'); ?>" method="post"> <form action="<?php echo site_url('contact/send_message'); ?>" method="post">
<input type="text" name="name" placeholder="Votre nom" required> <input type="text" name="name" placeholder="Votre nom" required>
<input type="email" name="email" placeholder="Votre email" required> <input type="email" name="email" placeholder="Votre email" required>
<textarea name="message" rows="5" placeholder="Votre message" required></textarea> <textarea name="message" rows="5" placeholder="Votre message" required></textarea>

View File

@ -16,7 +16,12 @@
<p>Nom: <?php echo htmlspecialchars($_POST['name']); ?></p> <p>Nom: <?php echo htmlspecialchars($_POST['name']); ?></p>
<p>Email: <?php echo htmlspecialchars($_POST['email']); ?></p> <p>Email: <?php echo htmlspecialchars($_POST['email']); ?></p>
<p>Message: <?php echo htmlspecialchars($_POST['message']); ?></p> <p>Message: <?php echo htmlspecialchars($_POST['message']); ?></p>
<a href="<?php echo site_url('accueil'); ?>"><button>Retour à l'accueil</button></a>
<?php if (!empty($_FILES['attachment']['name'])): ?>
<p>Fichier attaché: <?php echo htmlspecialchars($_FILES['attachment']['name']); ?></p>
<?php endif; ?>
<a href="<?php echo site_url('home'); ?>"><button>Retour à l'accueil</button></a>
</div> </div>
</div> </div>
</body> </body>

View File

@ -14,7 +14,7 @@
<div class="error"> <div class="error">
<h2>Votre message n'a pas pu être envoyé.</h2> <h2>Votre message n'a pas pu être envoyé.</h2>
<p>Veuillez réessayer ultérieurement ou nous contacter directement à l'adresse suivante : onzeur.contact@gmail.com</p> <p>Veuillez réessayer ultérieurement ou nous contacter directement à l'adresse suivante : onzeur.contact@gmail.com</p>
<a href="<?php echo site_url('accueil'); ?>"><button>Retour à l'accueil</button></a> <a href="<?php echo site_url('home'); ?>"><button>Retour à l'accueil</button></a>
</div> </div>
</div> </div>
</body> </body>

View File

@ -11,7 +11,7 @@
<span>|</span> <span>|</span>
<span>© 2024 Onzeur</span> <span>© 2024 Onzeur</span>
<span>|</span> <span>|</span>
<a href="#" class="legal-link">Nous contacter</a> <a href="<?php echo site_url('contact/index'); ?>" class="legal-link">Nous contacter</a>
</div> </div>
</div> </div>
</footer> </footer>

View File

@ -0,0 +1,83 @@
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
color: #640875;
}
.container {
width: 80%;
margin: 0 auto;
padding: 20px;
}
h1, h2, h3 {
color: #444;
}
.hero h1 {
color: #9f23b5;
}
.hero {
background-color: #2d1c30;
color: #fff;
padding: 50px 20px;
text-align: center;
}
.contact-form {
margin: 20px 0;
padding: 20px;
background: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
.contact-form h2 {
margin-top: 0;
}
.contact-form input, .contact-form textarea {
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 4px;
}
.contact-form button {
padding: 10px 20px;
background-color: #333;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
}
</style>
<title>Nous contacter - Onzeur</title>
</head>
<body>
<div class="hero">
<h1>Nous contacter</h1>
<p>N'hésitez pas à nous contacter pour toute question ou demande.</p>
</div>
<div class="container">
<div class="contact-form">
<h2>Formulaire de contact</h2>
<form action="<?php echo site_url('contact/send_detailed_message'); ?>" method="post" enctype="multipart/form-data">
<input type="text" name="name" placeholder="Votre nom" required><br>
<input type="email" name="email" placeholder="Votre email" required><br>
<textarea name="message" rows="5" placeholder="Votre message" required></textarea><br>
<input type="file" name="attachment"><br>
<button type="submit">Envoyer</button>
</form>
</div>
</div>
</body>
</html>