Loading src/UnicaenMail/Controller/MailController.php +10 −1 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace UnicaenMail\Controller; use UnicaenMail\Service\Mail\MailServiceAwareTrait; use UnicaenUtilisateur\Entity\Db\User; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; Loading Loading @@ -30,7 +31,15 @@ class MailController extends AbstractActionController { public function testAction() { return $this->redirect()->toRoute('mail', [], [], true); $request = $this->getRequest(); if ($request->isPost()) { $data = $request->getPost(); if(!isset($data['mail-to']) || !filter_var($data['mail-to'], FILTER_VALIDATE_EMAIL)) { return ['title' => "Envoyer un mail de test", 'error' => "L'adresse mail saisie n'est pas valide."]; } $this->getMailService()->sendMail($data['mail-to'], 'Mail de test', 'Ceci est un mail de test. <br/> <hr/>Merci de ne pas en tenir compte.'); } return ['title' => "Envoyer un mail de test"]; } public function reenvoiAction() Loading src/UnicaenMail/Entity/Db/Mail.php +3 −1 Original line number Diff line number Diff line Loading @@ -176,7 +176,9 @@ class Mail { */ public function setMotsClefs(array $motsClefs) : Mail { $this->motsClefs = implode(Mail::MOTCLEF_SEPARATEUR, $motsClefs); //Permet de s'assurer que les mots clefs ne sont pas vide $text = implode(Mail::MOTCLEF_SEPARATEUR, $motsClefs); $this->motsClefs = ($text && $text != '') ? $text : null; return $this; } Loading src/UnicaenMail/Service/Mail/MailService.php +0 −7 Original line number Diff line number Diff line Loading @@ -192,28 +192,22 @@ class MailService { $mail->setSujet($subject); $sujet = '['.$this->subjectPrefix.'] ' . $subject; if ($this->doNotSend) { $sujet .= ' {REDIR}'; } $message->setTo( (!is_array($mail->getDestinataires())) ? [ $mail->getDestinataires()] : $mail->getDestinataires()); $message->setSubject($sujet); $texte = "<p><i>Ce courrier électronique vous a été adressé <strong>automatiquement</strong> par l'application ".$this->subjectPrefix.". </i></p>" . $texte; $mail->setCorps($texte); $this->create($mail); if ($this->doNotSend) { $texte .= "<br/><br/><hr/><br/>"; $texte .= "Initialement envoyé à :"; $texte .= "<ul>"; foreach ($to as $t) $texte .= "<li>" . $t . "</li>"; $texte .= "</ul>"; } $parts = []; Loading @@ -233,7 +227,6 @@ class MailService { $attachement->setDisposition(Mime::DISPOSITION_ATTACHMENT); $parts[] = $attachement; } $body = new MimeMessage(); $body->setParts($parts); $message->setBody($body); Loading view/unicaen-mail/mail/test.phtml 0 → 100644 +38 −0 Original line number Diff line number Diff line <?php /** * @see \UnicaenMail\Controller\MailController::testAction() */ use UnicaenMail\Entity\Db\Mail; use UnicaenMail\Provider\Privilege\MailPrivileges; use UnicaenApp\View\Helper\Messenger; $this->headTitle($title); ?> <?php if(isset($error)) : ?> <div class="messenger alert alert-danger "> <?= $error ?></div> <?php endif; ?> <form action="mail/test" method="post"> <div> <label for="email">Destinataire : </label> <input type="email" name="mail-to" size="50" required> </div> <div> <button type="submit" name="send-mail-test" class="btn btn-primary" value="1"> <span class='icon mail'>Envoyer</span> </button> </div> </form> <script> $(function() { $("body").one("mail-test", function (event) { event.div.modal('hide'); window.location.reload(); }); }); </script> No newline at end of file Loading
src/UnicaenMail/Controller/MailController.php +10 −1 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace UnicaenMail\Controller; use UnicaenMail\Service\Mail\MailServiceAwareTrait; use UnicaenUtilisateur\Entity\Db\User; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; Loading Loading @@ -30,7 +31,15 @@ class MailController extends AbstractActionController { public function testAction() { return $this->redirect()->toRoute('mail', [], [], true); $request = $this->getRequest(); if ($request->isPost()) { $data = $request->getPost(); if(!isset($data['mail-to']) || !filter_var($data['mail-to'], FILTER_VALIDATE_EMAIL)) { return ['title' => "Envoyer un mail de test", 'error' => "L'adresse mail saisie n'est pas valide."]; } $this->getMailService()->sendMail($data['mail-to'], 'Mail de test', 'Ceci est un mail de test. <br/> <hr/>Merci de ne pas en tenir compte.'); } return ['title' => "Envoyer un mail de test"]; } public function reenvoiAction() Loading
src/UnicaenMail/Entity/Db/Mail.php +3 −1 Original line number Diff line number Diff line Loading @@ -176,7 +176,9 @@ class Mail { */ public function setMotsClefs(array $motsClefs) : Mail { $this->motsClefs = implode(Mail::MOTCLEF_SEPARATEUR, $motsClefs); //Permet de s'assurer que les mots clefs ne sont pas vide $text = implode(Mail::MOTCLEF_SEPARATEUR, $motsClefs); $this->motsClefs = ($text && $text != '') ? $text : null; return $this; } Loading
src/UnicaenMail/Service/Mail/MailService.php +0 −7 Original line number Diff line number Diff line Loading @@ -192,28 +192,22 @@ class MailService { $mail->setSujet($subject); $sujet = '['.$this->subjectPrefix.'] ' . $subject; if ($this->doNotSend) { $sujet .= ' {REDIR}'; } $message->setTo( (!is_array($mail->getDestinataires())) ? [ $mail->getDestinataires()] : $mail->getDestinataires()); $message->setSubject($sujet); $texte = "<p><i>Ce courrier électronique vous a été adressé <strong>automatiquement</strong> par l'application ".$this->subjectPrefix.". </i></p>" . $texte; $mail->setCorps($texte); $this->create($mail); if ($this->doNotSend) { $texte .= "<br/><br/><hr/><br/>"; $texte .= "Initialement envoyé à :"; $texte .= "<ul>"; foreach ($to as $t) $texte .= "<li>" . $t . "</li>"; $texte .= "</ul>"; } $parts = []; Loading @@ -233,7 +227,6 @@ class MailService { $attachement->setDisposition(Mime::DISPOSITION_ATTACHMENT); $parts[] = $attachement; } $body = new MimeMessage(); $body->setParts($parts); $message->setBody($body); Loading
view/unicaen-mail/mail/test.phtml 0 → 100644 +38 −0 Original line number Diff line number Diff line <?php /** * @see \UnicaenMail\Controller\MailController::testAction() */ use UnicaenMail\Entity\Db\Mail; use UnicaenMail\Provider\Privilege\MailPrivileges; use UnicaenApp\View\Helper\Messenger; $this->headTitle($title); ?> <?php if(isset($error)) : ?> <div class="messenger alert alert-danger "> <?= $error ?></div> <?php endif; ?> <form action="mail/test" method="post"> <div> <label for="email">Destinataire : </label> <input type="email" name="mail-to" size="50" required> </div> <div> <button type="submit" name="send-mail-test" class="btn btn-primary" value="1"> <span class='icon mail'>Envoyer</span> </button> </div> </form> <script> $(function() { $("body").one("mail-test", function (event) { event.div.modal('hide'); window.location.reload(); }); }); </script> No newline at end of file