mirror of
https://grond.iut-fbleau.fr/stiti/SAE_2.02
synced 2024-11-10 05:11:42 +01:00
62 lines
2.2 KiB
PHP
62 lines
2.2 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
use PHPMailer\PHPMailer\Exception;
|
|
|
|
require APPPATH . 'third_party/phpmailer/src/Exception.php';
|
|
require APPPATH . 'third_party/phpmailer/src/PHPMailer.php';
|
|
require APPPATH . 'third_party/phpmailer/src/SMTP.php';
|
|
|
|
|
|
class Contact extends CI_Controller {
|
|
|
|
public function __construct() {
|
|
parent::__construct();
|
|
// Chargez le modèle si nécessaire
|
|
}
|
|
|
|
public function index() {
|
|
// Vérifiez si le formulaire de contact a été soumis
|
|
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;
|
|
$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;
|
|
|
|
$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 {
|
|
$this->load->view('layout/header_dark');
|
|
$this->load->view('accueil');
|
|
$this->load->view('layout/footer_dark');
|
|
}
|
|
}
|
|
}
|