From 3b369122645b07b290f7fcc7bccb4787745cd5ea Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 24 Mar 2026 22:39:29 +0100 Subject: =?UTF-8?q?mode=20maintenance,=20optimisation=20moins=20de=20contr?= =?UTF-8?q?=C3=B4les=20en=20mode=20run,=20dossier=20service=20et=20d=C3=A9?= =?UTF-8?q?placement=20fichiers,=20sessions=20et=20entit=C3=A9=20User=20pr?= =?UTF-8?q?=C3=A9par=C3=A9es=20=C3=A0=20l'impl=C3=A9mentation=20hypoth?= =?UTF-8?q?=C3=A9tique=20des=20r=C3=B4les,=20entit=C3=A9=20AppMetadata,=20?= =?UTF-8?q?meilleure=20s=C3=A9curit=C3=A9=20de=20fillStartingDatabase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/EmailService.php | 102 --------------------------------------------------- 1 file changed, 102 deletions(-) delete mode 100644 src/EmailService.php (limited to 'src/EmailService.php') diff --git a/src/EmailService.php b/src/EmailService.php deleted file mode 100644 index c6d97b4..0000000 --- a/src/EmailService.php +++ /dev/null @@ -1,102 +0,0 @@ - exceptions - $mail->CharSet = 'UTF-8'; - - $smtp_host = $form_data->getData()['smtp_host'] ?? Config::$smtp_host; - $smtp_secure = $form_data->getData()['smtp_secure'] ?? Config::$smtp_secure; - $smtp_username = $form_data->getData()['smtp_username'] ?? Config::$smtp_username; - $smtp_password = $form_data->getData()['smtp_password'] ?? Config::$smtp_password; - $email_from = $form_data->getData()['email_from'] ?? Config::$email_from; // une adresse bidon est donnée à setFrom() - $email_from_name = $form_data->getData()['email_from_name'] ?? Config::$email_from_name; // = site web - $email_dest = $form_data->getData()['email_dest'] ?? Config::$email_dest; - $email_dest_name = $form_data->getData()['email_dest_name'] ?? Config::$email_dest_name; // = destinataire formulaire - - try{ - // Paramètres du serveur - $mail->isSMTP(); - $mail->Host = $smtp_host; - $mail->SMTPAuth = true; - $mail->Port = 25; - - if($mail->SMTPAuth){ - $mail->Username = $smtp_username; // e-mail - $mail->Password = $smtp_password; - $mail->SMTPSecure = $smtp_secure; // tls (starttls) ou ssl (smtps) - if($mail->SMTPSecure === 'tls'){ - $mail->Port = 587; - } - elseif($mail->SMTPSecure === 'ssl'){ - $mail->Port = 465; - } - } - //var_dump($mail->smtpConnect());die; // test de connexion - - // Expéditeur et destinataire - // $email_from, $email_from_name et $email_dest_name sont modifiables uniquement dans le config.ini pour l'instant - $mail->setFrom(strtolower($email_from), $email_from_name); - $mail->addAddress(strtolower($email_dest), $email_dest_name); - - // Contenu - $mail->isHTML(true); - if($test_email){ - $mail->Subject = "TEST d'un envoi d'e-mail depuis le site web"; - } - else{ - $mail->Subject = 'Message envoyé par: ' . $name . ' (' . $email . ') depuis le site web'; - } - $mail->Body = $message; - $mail->AltBody = $message; - - $mail->send(); - - // copie en BDD - if(!$test_email && ($form_data->getData()['keep_emails'] ?? self::KEEP_EMAILS_DEFAULT)){ - $db_email = new Email($name, $email, Config::$email_dest, $message, $form_data); - $entityManager->persist($db_email); - self::updateLastContactDate($entityManager, $email); - $entityManager->flush(); - } - - return true; - } - catch(Exception $e){ - echo "Le message n'a pas pu être envoyé. Erreur : {$e}
{$mail->ErrorInfo}"; - return false; - } - } - - static public function updateLastContactDate(EntityManager $entityManager, string $sender): void - { - foreach($entityManager->getRepository('App\Entity\Email')->findAll() as $email){ - $email->getSenderAddress() === $sender ? $email->updateLastContactDate() : null; - } - } - - // peut être appelée par bin/clean_emails_cron.php - static public function cleanEmails(EntityManager $entityManager): void - { - $emails = $entityManager->getRepository('App\Entity\Email')->findAll(); - foreach($emails as $email){ - if($email->getDeletionDate() < new \DateTime()){ - $entityManager->remove($email); - } - } - $entityManager->flush(); - } -} \ No newline at end of file -- cgit v1.2.3