Envoyer mail via mail_message
This commit is contained in:
parent
6ed4394dda
commit
ad67602483
1 changed files with 102 additions and 62 deletions
|
|
@ -23,9 +23,20 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function home(){
|
public function home(){
|
||||||
|
|
||||||
|
|
||||||
|
$intCategory = 0;
|
||||||
|
if (!empty($_GET['filter_cat'])) {
|
||||||
|
$intCategory = (int) $_GET['filter_cat'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$boolOld = false;
|
||||||
|
if (!empty($_GET['filter_old']) && $_GET['filter_old'] == 'true') {
|
||||||
|
$boolOld = true;
|
||||||
|
}
|
||||||
|
|
||||||
$objProjectModel = new ProjectModel;
|
$objProjectModel = new ProjectModel;
|
||||||
$arrProject = $objProjectModel->findAll();
|
$arrProject = $objProjectModel->findAll(0,'',0,0,'','','',$intCategory,$boolOld);
|
||||||
$arrProjectToDisplay = array();
|
$arrProjectToDisplay = array();
|
||||||
foreach($arrProject as $arrDetProject){
|
foreach($arrProject as $arrDetProject){
|
||||||
$objProject = new Project;
|
$objProject = new Project;
|
||||||
|
|
@ -34,8 +45,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_arrData['arrProjectToDisplay'] = $arrProjectToDisplay;
|
$this->_arrData['arrProjectToDisplay'] = $arrProjectToDisplay;
|
||||||
|
|
||||||
|
|
||||||
$this->_display("home");
|
$this->_display("home");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -43,8 +52,8 @@
|
||||||
/**
|
/**
|
||||||
* Fonction d'affichage de la barre de recherche
|
* Fonction d'affichage de la barre de recherche
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function search(){
|
public function search(){
|
||||||
|
|
||||||
//Récupérer les informations du formulaire
|
//Récupérer les informations du formulaire
|
||||||
$strKeywords = $_POST['keywords']??'';
|
$strKeywords = $_POST['keywords']??'';
|
||||||
$intAuthor = $_POST['author']??0;
|
$intAuthor = $_POST['author']??0;
|
||||||
|
|
@ -76,6 +85,7 @@
|
||||||
|
|
||||||
$this->_arrData['arrProjectToDisplay'] = $arrProjectToDisplay;
|
$this->_arrData['arrProjectToDisplay'] = $arrProjectToDisplay;
|
||||||
$this->_arrData['arrCategory'] = $arrCategory;
|
$this->_arrData['arrCategory'] = $arrCategory;
|
||||||
|
$this->_arrData['arrProject'] = $arrProject;
|
||||||
$this->_arrData['arrUser'] = $arrUser;
|
$this->_arrData['arrUser'] = $arrUser;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -87,62 +97,62 @@
|
||||||
/**
|
/**
|
||||||
* Fonction d'affichage de la page projet
|
* Fonction d'affichage de la page projet
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public function project (){
|
public function project (){
|
||||||
|
|
||||||
$objProjectModel = new ProjectModel;
|
$objProjectModel = new ProjectModel;
|
||||||
$arrProject = $objProjectModel->findAll(4);
|
$arrProject = $objProjectModel->findAll(4);
|
||||||
$arrProjectToDiplay = array();
|
$arrProjectToDisplay = array();
|
||||||
foreach($arrProject as $arrDetProject){
|
foreach($arrProject as $arrDetProject){
|
||||||
$objProject = new Project;
|
$objProject = new Project;
|
||||||
$objProject->hydrate($arrDetProject);
|
$objProject->hydrate($arrDetProject);
|
||||||
$arrProjectToDiplay[] = $objProject;
|
$arrProjectToDisplay[] = $objProject;
|
||||||
}
|
}
|
||||||
|
|
||||||
$objImageModel = new ImageModel;
|
$objImageModel = new ImageModel;
|
||||||
$arrImage = $objImageModel->findAllImage(4);
|
$arrImage = $objImageModel->findAllImage(4);
|
||||||
$arrImageToDiplay = array();
|
$arrImageToDisplay = array();
|
||||||
foreach($arrImage as $arrDetImage){
|
foreach($arrImage as $arrDetImage){
|
||||||
$objImage = new Image;
|
$objImage = new Image;
|
||||||
$objImage->hydrate($arrDetImage);
|
$objImage->hydrate($arrDetImage);
|
||||||
$arrImageToDiplay[] = $objImage;
|
$arrImageToDisplay[] = $objImage;
|
||||||
}
|
}
|
||||||
//Variable data
|
//Variable data
|
||||||
$_SESSION['title'] = $_POST['titleProject']??"";
|
$_SESSION['title'] = $_POST['titleProject']??"";
|
||||||
$_SESSION['description'] = $_POST['descProject']??"";
|
$_SESSION['description'] = $_POST['descProject']??"";
|
||||||
$_SESSION['content'] = $_POST['textProject']??"";
|
$_SESSION['content'] = $_POST['textProject']??"";
|
||||||
$_SESSION['thumbnail'] = $_FILES['imageProject']['name']??"";
|
$_SESSION['thumbnail'] = $_FILES['imageThumbnail']['name']??"";
|
||||||
$_SESSION['status'] = 'en_attente';
|
$_SESSION['status'] = 'en_attente';
|
||||||
|
$_SESSION['user_id'] = $_SESSION['user']['user_id'];
|
||||||
|
|
||||||
|
|
||||||
$objProject = new Project();
|
$objProject = new Project();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
/* Créer par Besnik le GOAT et l'autre GOAT de Guillaume
|
* Créer par Besnik le GOAT et l'autre GOAT de Guillaume
|
||||||
/*
|
*
|
||||||
/* @return bool pour savoir si le fichier existe,
|
* @return bool pour savoir si le fichier existe,
|
||||||
/* puis déplace vers le fichier uploads avec les images projet des utilisateurs
|
* puis déplace vers le fichier uploads avec les images projet des utilisateurs
|
||||||
/* Communication avec la BDD
|
* Communication avec la BDD
|
||||||
*/
|
*/
|
||||||
if (($_SESSION['thumbnail'] != null)){
|
if (($_SESSION['thumbnail'] != null)){
|
||||||
$strDest = "";
|
$strDest = "";
|
||||||
if ((count($_FILES) > 0) && ($_FILES['imageProject']['error'] != 4)){
|
if ((count($_FILES) > 0) && ($_FILES['imageProject']['error'] != 4)){
|
||||||
$strDest = '../public/uploads/projects/'.$_FILES['imageProject']['name'];
|
$strDest = 'uploads/projects/'.$_FILES['imageProject']['name'];
|
||||||
var_dump($strDest);
|
|
||||||
move_uploaded_file($_FILES['imageProject']['tmp_name'], $strDest);
|
move_uploaded_file($_FILES['imageProject']['tmp_name'], $strDest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** En cas d'appuis sur le bouton d'envoie ou celui de remettre a plus tard
|
/** En cas d'appuis sur le bouton d'envoie ou celui de remettre a plus tard
|
||||||
/* 1. Changement de status
|
* 1. Changement de status
|
||||||
/* 2. Hydratation avec les informations récupéré de l'utilisateur
|
* 2. Hydratation avec les informations récupéré de l'utilisateur
|
||||||
/* 3. Envoie des données à la BDD
|
* 3. Envoie des données à la BDD
|
||||||
*/
|
*/
|
||||||
if (isset($_POST['sendMessage'])) {
|
if (isset($_POST['sendMessage'])) {
|
||||||
$_SESSION['status'] = 'publié';
|
$_SESSION['status'] = 'publié';
|
||||||
$objProject->hydrate($_SESSION);
|
$objProject->hydrate($_SESSION);
|
||||||
$objProject->setThumbnail($strDest);
|
$objProject->setThumbnail($strDest);
|
||||||
|
var_dump($strDest);
|
||||||
|
var_dump($objProject);
|
||||||
$objProjectModel->insert($objProject);
|
$objProjectModel->insert($objProject);
|
||||||
|
|
||||||
} else if (isset($_POST['toContinue'])) {
|
} else if (isset($_POST['toContinue'])) {
|
||||||
|
|
@ -151,14 +161,12 @@
|
||||||
$objProjectModel->insert($objProject);
|
$objProjectModel->insert($objProject);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Débuggage
|
|
||||||
var_dump($_SESSION);
|
var_dump($_SESSION);
|
||||||
var_dump($objProject);
|
var_dump($objProject);
|
||||||
$this->_arrData['arrProjectToDiplay'] = $arrProjectToDiplay;
|
$this->_arrData['arrProjectToDiplay'] = $arrProjectToDisplay;
|
||||||
$this->_arrData['arrImageToDiplay'] = $arrImageToDiplay;
|
$this->_arrData['arrImageToDiplay'] = $arrImageToDisplay;
|
||||||
|
|
||||||
$this->_display("project");
|
$this->_display("project");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -174,7 +182,7 @@
|
||||||
$objProject->hydrate($arrProject);
|
$objProject->hydrate($arrProject);
|
||||||
|
|
||||||
$this->_arrData["objProject"] = $objProject;
|
$this->_arrData["objProject"] = $objProject;
|
||||||
$this->_display("projet_display");
|
$this->_display("project_display");
|
||||||
} else {
|
} else {
|
||||||
header("Location: index.php?ctrl=project&action=home");
|
header("Location: index.php?ctrl=project&action=home");
|
||||||
exit;
|
exit;
|
||||||
|
|
@ -187,16 +195,11 @@
|
||||||
|
|
||||||
public function sendEmail()
|
public function sendEmail()
|
||||||
{
|
{
|
||||||
if (count($_POST) > 0) {
|
if (count($_POST) > 0)
|
||||||
|
{
|
||||||
$projectId = (int)($_POST['project_id'] ?? 0);
|
$projectId = (int)($_POST['project_id'] ?? 0);
|
||||||
$toEmail = trim($_POST['to_email'] ?? '');
|
$toEmail = trim($_POST['to_email'] ?? '');
|
||||||
|
|
||||||
if ($projectId <= 0 || !filter_var($toEmail, FILTER_VALIDATE_EMAIL)) {
|
|
||||||
header("Location: index.php?ctrl=project&action=display&id=".$projectId."&mail=fail");
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
$objProjectModel = new ProjectModel();
|
$objProjectModel = new ProjectModel();
|
||||||
$arrProject = $objProjectModel->findOne($projectId);
|
$arrProject = $objProjectModel->findOne($projectId);
|
||||||
|
|
||||||
|
|
@ -208,46 +211,37 @@
|
||||||
$objProject = new Project();
|
$objProject = new Project();
|
||||||
$objProject->hydrate($arrProject);
|
$objProject->hydrate($arrProject);
|
||||||
|
|
||||||
|
$objMail = new PHPMailer();
|
||||||
|
|
||||||
$objMail = new PHPMailer(); // Nouvel objet Mail
|
|
||||||
$objMail->IsSMTP();
|
$objMail->IsSMTP();
|
||||||
$objMail->Mailer = "smtp";
|
$objMail->Mailer = "smtp";
|
||||||
$objMail->CharSet = PHPMailer::CHARSET_UTF8;
|
$objMail->CharSet = PHPMailer::CHARSET_UTF8;
|
||||||
|
$objMail->SMTPDebug = 0;
|
||||||
|
|
||||||
$objMail->SMTPDebug = 0;
|
$objMail->SMTPAuth = true;
|
||||||
|
$objMail->SMTPSecure = "tls";
|
||||||
$objMail->SMTPAuth = TRUE;
|
$objMail->Port = 587;
|
||||||
$objMail->SMTPSecure = "tls";
|
$objMail->Host = 'smtp-relay.brevo.com';
|
||||||
$objMail->Port = 587;
|
$objMail->Username = 'a2a67e001@smtp-brevo.com';
|
||||||
$objMail->Host = "smtp.gmail.com";
|
$objMail->Password = 'xsmtpsib-f2af87e12d3db6f1b99802a92c1acda32d45fc32a8446eeed7e49ec91c4ec7ef-AX8Y7YkRWYSmKHwS';
|
||||||
$objMail->Username = "projet.folliow@gmail.com";
|
|
||||||
$objMail->Password = "dqnw mqbu cwvg enbp";
|
|
||||||
|
|
||||||
$objMail->IsHTML(true);
|
$objMail->IsHTML(true);
|
||||||
|
|
||||||
|
$objMail->setFrom('projet.folliow@hotmail.com', 'Folliow');
|
||||||
$objMail->setFrom('projet.folliow@gmail.com', 'Projet Folliow');
|
|
||||||
|
|
||||||
|
|
||||||
// Destinataire
|
|
||||||
$objMail->addAddress($toEmail);
|
$objMail->addAddress($toEmail);
|
||||||
|
|
||||||
// Mail
|
|
||||||
$objMail->Subject = "Projet : " . $objProject->getTitle();
|
$objMail->Subject = "Projet : " . $objProject->getTitle();
|
||||||
|
|
||||||
$url = "http://localhost/projet_php/public/index.php?ctrl=project&action=display&id=" . $projectId;
|
$url = "https://php.boulayoune.com/index.php?ctrl=project&action=display&id=" . $projectId;
|
||||||
|
|
||||||
$objMail->Body =
|
$this->_arrData['projectTitle'] = $objProject->getTitle();
|
||||||
"<h3>" . $objProject->getTitle() . "</h3>" .
|
$this->_arrData['projectDescription'] = $objProject->getDescription();
|
||||||
"<p>" . $objProject->getDescription() . "</p>" .
|
$this->_arrData['projectUrl'] = $url;
|
||||||
"<p><a href='" . $url . "'>Voir le projet</a></p>";
|
|
||||||
|
$objMail->Body = $this->_display("mail_message", false);
|
||||||
|
|
||||||
// Envoi + redirection
|
|
||||||
if ($objMail->Send()) {
|
if ($objMail->Send()) {
|
||||||
header("Location: index.php?ctrl=project&action=display&id=".$projectId."&mail=ok");
|
header("Location: index.php?ctrl=project&action=display&id=".$projectId."&mail=ok");
|
||||||
} else {
|
} else {
|
||||||
// Pour debug si besoin: echo $objMail->ErrorInfo; exit;
|
|
||||||
header("Location: index.php?ctrl=project&action=display&id=".$projectId."&mail=fail");
|
header("Location: index.php?ctrl=project&action=display&id=".$projectId."&mail=fail");
|
||||||
}
|
}
|
||||||
exit;
|
exit;
|
||||||
|
|
@ -256,4 +250,50 @@
|
||||||
header("Location: index.php?ctrl=project&action=home");
|
header("Location: index.php?ctrl=project&action=home");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function accept(){
|
||||||
|
|
||||||
|
//Récupéré l'id dans l'url
|
||||||
|
$intId = $_GET['id'];
|
||||||
|
|
||||||
|
//Je créer un nouveau model pour exec la commande SQL
|
||||||
|
$objProjectModel = new ProjectModel;
|
||||||
|
$objProjectModel->accept($intId);
|
||||||
|
|
||||||
|
//Redirection vers la page
|
||||||
|
header("Location: index.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function refuse(){
|
||||||
|
|
||||||
|
//Récupéré l'id dans l'url
|
||||||
|
$intId = $_GET['id'];
|
||||||
|
|
||||||
|
//Je créer un nouveau model pour exec la commande SQL
|
||||||
|
$objProjectModel = new ProjectModel;
|
||||||
|
$objProjectModel->refuse($intId);
|
||||||
|
|
||||||
|
//Redirection vers la page
|
||||||
|
header("Location: index.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(){
|
||||||
|
|
||||||
|
//Récupéré l'id dans l'url
|
||||||
|
$intId = $_GET['id'];
|
||||||
|
|
||||||
|
//Je créer un nouveau model pour exec la commande SQL
|
||||||
|
$objProjectModel = new ProjectModel;
|
||||||
|
$objProjectModel->delete($intId);
|
||||||
|
|
||||||
|
//Redirection vers la page
|
||||||
|
header("Location: index.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue