src/Services/SendContactEmail.php line 66

Open in your IDE?
  1. <?php
  2. namespace App\Services;
  3. use App\Entity\AccountingFirm;
  4. use App\Entity\Announcement;
  5. use App\Entity\ApplyRequest;
  6. use App\Entity\Contact;
  7. use App\Entity\ContactCustom;
  8. use App\Entity\ContactEtreRappele;
  9. use App\Entity\ContactInvestissementImmoProperty;
  10. use App\Entity\ContactInvestissementImmoPropertyCharge;
  11. use App\Entity\ContactPipelineStep;
  12. use App\Entity\ContactProfession;
  13. use App\Entity\ContactSubjectType;
  14. use App\Entity\DemandeCompany;
  15. use App\Entity\DemandeNewsletter;
  16. use App\Entity\Ebook;
  17. use App\Entity\MailjetApi;
  18. use App\Entity\Prescriber;
  19. use App\Repository\AccountingFirmRepository;
  20. use DateTime;
  21. use DateTimeImmutable;
  22. use Doctrine\ORM\EntityManagerInterface;
  23. use Mailjet\Client;
  24. use Mailjet\Resources;
  25. use Qferrer\Mjml\Twig\MjmlExtension;
  26. use Symfony\Component\Filesystem\Filesystem;
  27. use Symfony\Component\HttpFoundation\File\Exception\FileException;
  28. use Symfony\Component\HttpFoundation\Request;
  29. use Symfony\Component\HttpFoundation\RequestStack;
  30. use Symfony\Component\Mime\Address;
  31. use Symfony\Component\Mime\Email;
  32. use Twig\Environment;
  33. class SendContactEmail
  34. {
  35.     protected $entityManager;
  36.     protected $requestStack;
  37.     protected $mailjetApiEncryptionService;
  38.     protected MjmlExtension $mjmlRenderer;
  39.     protected Environment $twig;
  40.     private $accountingFirm;
  41.     private $mailer;
  42.     private $mailjet_username;
  43.     private $mailjet_password;
  44.     private ?Client $mj null;
  45.     public function __construct(CustomMailer $mailerAccountingFirmRepository $accountingFirmRepositoryEntityManagerInterface $entityManagerRequestStack $requestStackMailjetApiEncryptionService $mailjetApiEncryptionServiceMjmlExtension $mjmlRendererEnvironment $twig)
  46.     {
  47.         $this->entityManager $entityManager;
  48.         $this->requestStack $requestStack;
  49.         $this->mailjetApiEncryptionService $mailjetApiEncryptionService;
  50.         $this->mjmlRenderer $mjmlRenderer;
  51.         $this->twig $twig;
  52.         $theHost Request::createFromGlobals()->getHost();
  53.         $theHost str_replace('www.'''$theHost);
  54.         $this->theHost $theHost;
  55.         if (preg_match('/preview/'$this->requestStack->getCurrentRequest()->get('_route'))) {
  56.             $theHost $this->requestStack->getCurrentRequest()->attributes->get('host');
  57.         }
  58.         $this->accountingFirm $accountingFirmRepository->findOneBy([
  59.             'host' => $theHost
  60.         ]);
  61.         if ($this->accountingFirm != null && $this->accountingFirm->getParameters()->getMailjetapi() != null) {
  62.             $mailjetApi $this->mailjetApiEncryptionService->decryptMailjetApi($this->accountingFirm->getParameters()->getMailjetapi());
  63.             $this->mailjet_username $mailjetApi->getUsername();
  64.             $this->mailjet_password $mailjetApi->getPassword();
  65.             $this->mailer $mailer->getMailer($this->mailjet_username$this->mailjet_password);
  66.         } else {
  67.             $mailjetApiRepository $this->entityManager->getRepository(MailjetApi::class);
  68.             $mailjetApi $this->mailjetApiEncryptionService->decryptMailjetApi($mailjetApiRepository->findOneBy(['id' => 1]));
  69.             $this->mailer $mailer->getMailer($mailjetApi->getUsername(), $mailjetApi->getPassword());
  70.         }
  71.         if ($this->requestStack->getCurrentRequest()->get('_route') == "identite_visuelle_edit") {
  72.             $mailjetApiRepository $this->entityManager->getRepository(MailjetApi::class);
  73.             $mailjetApi $this->mailjetApiEncryptionService->decryptMailjetApi($mailjetApiRepository->findOneBy(['id' => 2]));
  74.             $this->mailer $mailer->getMailer($mailjetApi->getUsername(), $mailjetApi->getPassword());
  75.         }
  76.         $this->mailjetApiEncryptionService $mailjetApiEncryptionService;
  77.     }
  78.     private function initMailjet(?MailjetApi $mailjetApi): void
  79.     {
  80.         if (!$mailjetApi) {
  81.             throw new \RuntimeException('Missing Mailjet API credentials');
  82.         }
  83.         $decrypted $this->mailjetApiEncryptionService->decryptMailjetApi($mailjetApi);
  84.         $this->mj = new Client(
  85.             $decrypted->getUsername(),
  86.             $decrypted->getPassword(),
  87.             true,
  88.             ['version' => 'v3.1']
  89.         );
  90.     }
  91.     private function sendMailjet(
  92.         array $from,
  93.         array $to,
  94.         string $subject,
  95.         string $htmlPart,
  96.         ?array $cc null
  97.     ): ?string {
  98.         if (!$this->mj) {
  99.             return "NO_MAILJET_CLIENT";
  100.         }
  101.         $message = [
  102.             'From'     => $from,
  103.             'To'       => $to,
  104.             'Subject'  => $subject,
  105.             'HTMLPart' => $htmlPart,
  106.         ];
  107.         if ($cc) {
  108.             $message['Cc'] = $cc;
  109.         }
  110.         $body = ['Messages' => [$message]];
  111.         try {
  112.             $response $this->mj->post(Resources::$Email, ['body' => $body]);
  113.             if ($response->success()) {
  114.                 return "SEND";
  115.             }
  116.             return "ERROR_SENDING";
  117.         } catch (\Throwable $e) {
  118.             return "ERROR_SENDING";
  119.         }
  120.     }
  121.     private function getInternalMailjetApi(): ?MailjetApi
  122.     {
  123.         return $this->entityManager->getRepository(MailjetApi::class)->findOneBy(['id' => 1]);
  124.     }
  125.     public function sendContactEmail($form)
  126.     {
  127.         $configEmail $this->accountingFirm->getParameters()->getWebMail();
  128.         if (null != $configEmail) {
  129.             $mailbody '
  130.                 <h1>Vous avez reçus une demande de contact depuis votre site web.</h1>
  131.                 <p>Sujet : ' $form['subjectType']->getData() . '</p>
  132.                 <p>Nom : ' $form['name']->getData() . '</p>
  133.                 <p>Téléphone : ' $form['phone']->getData() . '</p>
  134.                 <p>Email : ' $form['email']->getData() . '</p>
  135.                 <p>Message :</p>
  136.                 <p>' $form['message']->getData() . '</p>
  137.                 <br/>
  138.                 <p>Provenance : ' $form['page']->getData() . '</p>
  139.             ';
  140.             $email = (new Email())
  141.                 ->from($configEmail)
  142.                 ->to($configEmail)
  143.                 ->subject('Demande en ligne')
  144.                 ->html($mailbody);
  145.             $this->mailer->send($email);
  146.             $contact = new Contact();
  147.             $contact->setAccountingFirm($this->accountingFirm);
  148.             $contact->setSubjectType($form['subjectType']->getData());
  149.             $contact->setName($form['name']->getData());
  150.             $contact->setEmail($form['email']->getData());
  151.             $contact->setPhone($form['phone']->getData());
  152.             $contact->setMessage($form['message']->getData());
  153.             $contact->setPage($form['page']->getData());
  154.             $contact->setDateadd(new DateTime('now'));
  155.             if ($form['subjectType']->getData()->getSlug() === ContactSubjectType::PROSPECT || $form['subjectType']->getData()->getSlug() === ContactSubjectType::DEMANDE_DEVISE) {
  156.                 $contact->setCurrentStep($this->entityManager->getRepository(ContactPipelineStep::class)->findOneByPosition(1));
  157.             }
  158.             $this->entityManager->persist($contact);
  159.             $this->entityManager->flush();
  160.             $mailbody_confirm '
  161.                 <p>Bonjour,</p>
  162.                 <p>Votre demande a été envoyée avec succès. Nous allons vous recontacter dans les plus brefs délais. Merci de votre confiance.</p>
  163.                 <p>En soumettant ce formulaire, j\'accepte que les informations saisies soient exploitées dans le cadre de la demande de devis et de la relation commerciale qui peuvent en découler.</p>
  164.             ';
  165.             $email_confirm = (new Email())
  166.                 ->from($configEmail)
  167.                 ->to($form['email']->getData())
  168.                 //->cc('cc@example.com')
  169.                 //->replyTo('fabien@example.com')
  170.                 //->priority(Email::PRIORITY_HIGH)
  171.                 ->subject('Confirmation d\'envoi de votre message')
  172.                 ->html($mailbody_confirm);
  173.             $this->mailer->send($email_confirm);
  174.             if ($form['route']->getData() == "previewprescripteur_client" || $form['route']->getData() == "prescripteur_client") {
  175.                 $idPrescriber $form['id_prescriber']->getData();
  176.                 $contactPrescriber $this->entityManager->getRepository(Prescriber::class)->findOneBy(['id' => $idPrescriber]);
  177.                 if ($contactPrescriber) {
  178.                     $mailbody_prescriber '
  179.                         <p>Bonjour,</p>
  180.                         <p>Une demande vient d’être déposée sur le site du <strong>Propuls’Cab</strong> suite à votre recommandation.</p>
  181.                         <p>Elle est actuellement en cours de traitement par notre équipe. Vous recevrez prochainement des informations concernant les suites apportées à cette prise de contact.</p>
  182.                         <p>Merci pour votre confiance.</p>
  183.                         <p>
  184.                             -- <br>
  185.                             Bien cordialement, <br>
  186.                             <strong>Joseph MISRAHI</strong> <br>
  187.                             <strong>Expert-comptable Associé du cabinet Propuls’cab</strong> <br>
  188.                         </p>
  189.                     ';
  190.                     $email_prescriber = (new Email())
  191.                         ->from($configEmail)
  192.                         ->to($contactPrescriber->getMail())
  193.                         //->cc('cc@example.com')
  194.                         ->bcc('tristan.meillat28@gmail.com')
  195.                         //->replyTo('fabien@example.com')
  196.                         //->priority(Email::PRIORITY_HIGH)
  197.                         ->subject('Nouvelle demande reçue via Propuls’Cab')
  198.                         ->html($mailbody_prescriber);
  199.                 }
  200.                 $this->mailer->send($email_prescriber);
  201.             }
  202.         }
  203.     }
  204.     public function sendRecrutementEmail($form)
  205.     {
  206.         $configEmail $this->accountingFirm->getParameters()->getWebMail();
  207.         $contact = new ApplyRequest();
  208.         $filesystem = new Filesystem();
  209.         $cv $form['tmpCV']->getData();
  210.         $lm $form['tmpLettre']->getData();
  211.         if ($cv) {
  212.             $directory '../public/cvs/';
  213.             try {
  214.                 if (!$filesystem->exists($directory)) {
  215.                     $filesystem->mkdir($directory);
  216.                 }
  217.                 $originalFilename pathinfo($cv->getClientOriginalName(), PATHINFO_FILENAME);
  218.                 $fileNamecv $originalFilename '-' uniqid() . '.' $cv->guessExtension();
  219.                 $cv->move($directory$fileNamecv);
  220.                 $contact->setCv($fileNamecv);
  221.             } catch (FileException $e) {
  222.             }
  223.         }
  224.         if ($lm) {
  225.             $directory '../public/lms/';
  226.             try {
  227.                 if (!$filesystem->exists($directory)) {
  228.                     $filesystem->mkdir($directory);
  229.                 }
  230.                 $originalFilename pathinfo($lm->getClientOriginalName(), PATHINFO_FILENAME);
  231.                 $fileNamelm $originalFilename '-' uniqid() . '.' $lm->guessExtension();
  232.                 $lm->move($directory$fileNamelm);
  233.                 $contact->setLettre($fileNamelm);
  234.             } catch (FileException $e) {
  235.             }
  236.         }
  237.         if (null != $configEmail) {
  238.             $mailbody '
  239.                 <h1>Vous avez reçus une réponse à votre annonce de recrutement depuis votre site web.</h1>
  240.                 <p>Nom : ' $form['nom']->getData() . '</p>
  241.                 <p>Téléphone : ' $form['tel']->getData() . '</p>
  242.                 <p>Email : ' $form['email']->getData() . '</p>
  243.                 <p>Message :</p>
  244.                 <p>' $form['message']->getData() . '</p>
  245.                 <br/>
  246.             ';
  247.             if ($fileNamecv and !$fileNamelm) {
  248.                 $email = (new Email())
  249.                     ->from($configEmail)
  250.                     ->to($configEmail)
  251.                     ->subject('Demande en ligne')
  252.                     ->html($mailbody)
  253.                     ->attach(fopen("../public/cvs/" $fileNamecv'r'), $fileNamecv);
  254.             } elseif (!$fileNamecv and $fileNamelm) {
  255.                 $email = (new Email())
  256.                     ->from($configEmail)
  257.                     ->to($configEmail)
  258.                     ->subject('Demande en ligne')
  259.                     ->html($mailbody)
  260.                     ->attach(fopen("../public/lms/" $fileNamelm'r'), $fileNamelm);
  261.             } elseif (!$fileNamecv and !$fileNamelm) {
  262.                 $email = (new Email())
  263.                     ->from($configEmail)
  264.                     ->to($configEmail)
  265.                     ->subject('Demande en ligne')
  266.                     ->html($mailbody);
  267.             } else { // lm and cv defined
  268.                 $email = (new Email())
  269.                     ->from($configEmail)
  270.                     ->to($configEmail)
  271.                     ->subject('Demande en ligne')
  272.                     ->html($mailbody)
  273.                     ->attach(fopen("../public/cvs/" $fileNamecv'r'), $fileNamecv)
  274.                     ->attach(fopen("../public/lms/" $fileNamelm'r'), $fileNamelm);
  275.             }
  276.             $this->mailer->send($email);
  277.             $contact->setDate(new DateTime('now'));
  278.             $contact->setNom($form['nom']->getData());
  279.             $contact->setEmail($form['email']->getData());
  280.             $contact->setTel($form['tel']->getData());
  281.             $contact->setMessage($form['message']->getData());
  282.             //$contact->setCv($form['cv']->getData());
  283.             //$contact->setLettre($form['lettre']->getData());
  284.             $contact->setRgpd($form['rgpd']->getData());
  285.             $annonceRepo $this->entityManager->getRepository(Announcement::class);
  286.             $annonce $annonceRepo->findOneBy(['id' => $form['announcementId']->getData()]);
  287.             $contact->setAnnonce($annonce);
  288.             $this->entityManager->persist($contact);
  289.             $this->entityManager->flush();
  290.             $mailbody_confirm '
  291.                 <p>Bonjour,</p>
  292.                 <p>Votre demande a été envoyée avec succès. Nous allons vous recontacter dans les plus brefs délais. Merci de votre confiance.</p>
  293.                 <p>En soumettant ce formulaire, j\'accepte que les informations saisies soient exploitées dans le cadre de la demande de devis et de la relation commerciale qui peuvent en découler.</p>
  294.             ';
  295.             $email_confirm = (new Email())
  296.                 ->from($configEmail)
  297.                 ->to($form['email']->getData())
  298.                 //->cc('cc@example.com')
  299.                 //->replyTo('fabien@example.com')
  300.                 //->priority(Email::PRIORITY_HIGH)
  301.                 ->subject('Confirmation d\'envoi de votre message')
  302.                 ->html($mailbody_confirm);
  303.             $this->mailer->send($email_confirm);
  304.         }
  305.     }
  306.     public function sendEbookEmail($form_livre)
  307.     {
  308.         $ebookData $this->entityManager->getRepository(Ebook::class)->findOneBy(['id' => $form_livre['ebookId']->getData()]);
  309.         if (!is_null($ebookData)) {
  310.             $configEmail $this->accountingFirm->getParameters()->getWebMail();
  311.             if (null != $configEmail) {
  312.                 $mailbody '
  313.                     <h1>Quelqu\'un a téléchargé un livre blanc :</h1>
  314.                     <p>Nom : ' $form_livre['surname']->getData() . '</p>
  315.                     <p>Prénom : ' $form_livre['name']->getData() . '</p>
  316.                     <p>Société : ' $form_livre['company']->getData() . '</p>
  317.                     <p>Fonction : ' $form_livre['function']->getData() . '</p>
  318.                     <p>Adresse : ' $form_livre['adress']->getData() . '</p>
  319.                     <p>Activité : ' $form_livre['activity']->getData() . '</p>
  320.                     <p>Téléphone : ' $form_livre['phone']->getData() . '</p>
  321.                     <p>Email : ' $form_livre['email']->getData() . '</p>
  322.                     <br/>
  323.                     <p>Livre blanc : ' $form_livre['ebookId']->getData() . ' | ' $ebookData->getTitle() . '</p>
  324.                     <p>Provenance : ' $form_livre['page']->getData() . '</p>
  325.                     ';
  326.                 $email = (new Email())
  327.                     ->from($configEmail)
  328.                     ->to($configEmail)
  329.                     //->cc('cc@example.com')
  330.                     ->subject('Téléchargement d\'un livre blanc')
  331.                     ->html($mailbody);
  332.                 $this->mailer->send($email);
  333.                 $mailbody_confirm "
  334.                     <p>Bonjour</p>
  335.                     <br><br>
  336.                     <p>Nous avons le plaisir de vous envoyer ce livre blanc " $ebookData->getTitle() . ",
  337.                         nous vous invitons &agrave; le t&eacute;l&eacute;charger &agrave; partir de ce lien : <a target=\"_blank\" href=\"https://" $this->theHost '/medias/documents/' $ebookData->getDocuments()->first()->getName() . "\">Télécharger</a>
  338.                     </p><br>
  339.                     <p>Bonne lecture,<br>L'&eacute;quipe " $this->accountingFirm->getName() . ".</p>
  340.                     ";
  341.                 $email_confirm = (new Email())
  342.                     ->from($configEmail)
  343.                     ->to($form_livre['email']->getData())
  344.                     //->cc('cc@example.com')
  345.                     //->replyTo('fabien@example.com')
  346.                     //->priority(Email::PRIORITY_HIGH)
  347.                     ->subject('Confirmation d\'envoi de votre message')
  348.                     ->html($mailbody_confirm);
  349.                 $this->mailer->send($email_confirm);
  350.             }
  351.         } else {
  352.             //die('🐛 SPAM !');
  353.         }
  354.     }
  355.     public function sendCompanyEmail($form_company)
  356.     {
  357.         $configEmail $this->accountingFirm->getParameters()->getWebMail();
  358.         if (null != $configEmail) {
  359.             $mailbody '
  360.        <h1>Demande de création d\'entreprise :</h1>
  361.          <p>Forme juridique retenue  : ' $form_company['formeJuridique']->getData() . '</p>
  362.           <p>Capital social : ' $form_company['capital']->getData() . '</p>
  363.            <p>Nature de l\'activité  : ' $form_company['activite']->getData() . '</p>
  364.             <p>Date de début d\'activité  : ' $form_company['dateDebutActivite']->getData()->format('Y-m-d') . '</p>
  365.              <p>Nombre d\'associés  : ' $form_company['nbAssocie']->getData() . '</p>
  366.             <p>Nombre d\'actions  : ' $form_company['nbAction']->getData() . '</p>
  367.             <p>Valeur nominale des actions  : ' $form_company['valeurAction']->getData() . '</p>
  368.             <p>Nom : ' $form_company['name']->getData() . '</p>
  369.             <p>Prénom : ' $form_company['surname']->getData() . '</p>
  370.             <p>Téléphone : ' $form_company['phone']->getData() . '</p>
  371.             <p>Email : ' $form_company['email']->getData() . '</p>
  372.                     <br/>
  373.                     ';
  374.             $email = (new Email())
  375.                 ->from($configEmail)
  376.                 ->to($configEmail)
  377.                 //->cc('cc@example.com')
  378.                 //->replyTo('fabien@example.com')
  379.                 //->priority(Email::PRIORITY_HIGH)
  380.                 ->subject('Demande de création d\'entreprise')
  381.                 ->html($mailbody);
  382.             $this->mailer->send($email);
  383.             $company = new DemandeCompany();
  384.             $company->setAccountingFirm($this->accountingFirm);
  385.             $company->setFormeJuridique($form_company['formeJuridique']->getData());
  386.             $company->setCapital($form_company['capital']->getData());
  387.             $company->setActivite($form_company['activite']->getData());
  388.             $company->setDateDebutActivite($form_company['dateDebutActivite']->getData());
  389.             $company->setNbAction($form_company['nbAction']->getData());
  390.             $company->setNbAssocie($form_company['nbAssocie']->getData());
  391.             $company->setValeurAction($form_company['valeurAction']->getData());
  392.             $company->setSurname($form_company['surname']->getData());
  393.             $company->setPhone($form_company['phone']->getData());
  394.             $company->setPage($form_company['page']->getData());
  395.             $company->setRgpd($form_company['rgpd']->getData());
  396.             $company->setName($form_company['name']->getData());
  397.             $company->setEmail($form_company['email']->getData());
  398.             $company->setDateadd(new DateTime('now'));
  399.             $this->entityManager->persist($company);
  400.             $this->entityManager->flush();
  401.             $mailbody_confirm "
  402.                     <p>Bonjour</p>
  403.                     <br><br>
  404.                 <p>Votre demande a été envoyée avec succès. Nous allons vous recontacter dans les plus brefs délais. Merci de votre confiance.</p>
  405.                 <p>En soumettant ce formulaire, j\'accepte que les informations saisies soient exploitées dans le cadre de la demande de devis et de la relation commerciale qui peuvent en découler.</p><br>L'&eacute;quipe " $this->accountingFirm->getName() . ".</p>
  406.                     ";
  407.             $email_confirm = (new Email())
  408.                 ->from($configEmail)
  409.                 ->to($form_company['email']->getData())
  410.                 //->cc('cc@example.com')
  411.                 //->replyTo('fabien@example.com')
  412.                 //->priority(Email::PRIORITY_HIGH)
  413.                 ->subject('Confirmation d\'envoi de votre message')
  414.                 ->html($mailbody_confirm);
  415.             $this->mailer->send($email_confirm);
  416.         }
  417.     }
  418.     public function sendMiniEbookEmail($form_minibook)
  419.     {
  420.         if (empty(trim($form_minibook['hp']->getData()))) {
  421.             $configEmail $this->accountingFirm->getParameters()->getWebMail();
  422.             if (null != $configEmail) {
  423.                 $mailbody '
  424.                 <h3>Nouvelle demande de livre blanc : </h3>
  425.                 <p><strong>Nom :</strong> ' $form_minibook['name']->getData() . '</p>
  426.                 <p><strong>Email :</strong> ' $form_minibook['email']->getData() . '</p>
  427.                 ';
  428.                 $email = (new Email())
  429.                     ->from($configEmail)
  430.                     ->to($configEmail)
  431.                     //->cc('cc@example.com')
  432.                     //->replyTo('fabien@example.com')
  433.                     //->priority(Email::PRIORITY_HIGH)
  434.                     ->subject('Demande livre blanc')
  435.                     ->html($mailbody);
  436.                 // $this->mailer->send($email);
  437.                 $this->form_send_minibook true;
  438.                 $mailbody_confirm '
  439.                 <p>Bonjour,</p>
  440.                 <p>Suite à votre demande, veuillez trouver le livre blanc pour connaitre l\'ensemble des étapes pour créer votre entreprise en toute sérénité : http://faace.fr/assets/pdf/livre-blanc.pdf </p><p><br> A bientôt sur www.faace.fr.</p>
  441.                 ';
  442.                 $email_confirm = (new Email())
  443.                     ->from($configEmail)
  444.                     ->to($form_minibook['email']->getData())
  445.                     //->cc('cc@example.com')
  446.                     //->replyTo('fabien@example.com')
  447.                     //->priority(Email::PRIORITY_HIGH)
  448.                     ->subject('Demande livre blanc')
  449.                     ->html($mailbody_confirm);
  450.                 //$this->mailer->send($email_confirm);
  451.             }
  452.         } else {
  453.             //die('🐛 SPAM !');
  454.         }
  455.     }
  456.     public function sendNewsletterEmail($form_newsletter)
  457.     {
  458.         if (empty(trim($form_newsletter['hp']->getData()))) {
  459.             $configEmail $this->accountingFirm->getParameters()->getWebMail();
  460.             if (null != $configEmail) {
  461.                 $mailbody '
  462.                 <h1>Vous avez reçus une demande de d\'inscription newsletter  depuis votre site web.</h1>
  463.                 <p>Nom : ' $form_newsletter['name']->getData() . '</p>
  464.                 <p>Email : ' $form_newsletter['email']->getData() . '</p>
  465.                 ';
  466.                 $email = (new Email())
  467.                     ->from($configEmail)
  468.                     ->to($configEmail)
  469.                     //->cc('cc@example.com')
  470.                     //->replyTo('fabien@example.com')
  471.                     //->priority(Email::PRIORITY_HIGH)
  472.                     ->subject('Demande inscription newsletter')
  473.                     ->html($mailbody);
  474.                 $this->mailer->send($email);
  475.                 $newletter = new DemandeNewsletter();
  476.                 $newletter->setAccountingFirm($this->accountingFirm);
  477.                 $newletter->setName($form_newsletter['name']->getData());
  478.                 $newletter->setEmail($form_newsletter['email']->getData());
  479.                 $newletter->setDateadd(new DateTime('now'));
  480.                 $this->entityManager->persist($newletter);
  481.                 $this->entityManager->flush();
  482.                 $mailbody_confirm '
  483.                 <p>Bonjour,</p>
  484.                 <p>Votre inscription à notre newsletter a bien été enregistrée. </p>
  485.                 ';
  486.                 $email_confirm = (new Email())
  487.                     ->from($configEmail)
  488.                     ->to($form_newsletter['email']->getData())
  489.                     //->cc('cc@example.com')
  490.                     //->replyTo('fabien@example.com')
  491.                     //->priority(Email::PRIORITY_HIGH)
  492.                     ->subject('Confirmation d\'inscription newsletter')
  493.                     ->html($mailbody_confirm);
  494.                 $this->mailer->send($email_confirm);
  495.             }
  496.         } else {
  497.             //die('🐛 SPAM !');
  498.         }
  499.     }
  500.     public function sendEmail($mailbody$to$subject)
  501.     {
  502.         /*  $contact = $args->getEntity();
  503.         if (!$contact instanceof Contact) {
  504.             return;
  505.         }*/
  506.         $configEmail $this->accountingFirm->getParameters()->getWebMail();
  507.         if (null != $configEmail) {
  508.             $email = (new Email())
  509.                 ->from($configEmail)
  510.                 ->to($to)
  511.                 ->subject($subject)
  512.                 ->html($mailbody);
  513.             $this->mailer->send($email);
  514.         }
  515.     }
  516.     public function sendContactCustomEmail($form_custom)
  517.     {
  518.         $configEmail $this->accountingFirm->getParameters()->getWebMail();
  519.         if (null != $configEmail) {
  520.             $mailbody '
  521.                 <h1>Vous avez reçus une demande de contact depuis votre site web.</h1>
  522.                 <p>Nom : ' $form_custom['name']->getData() . '</p>
  523.                 <p>Téléphone : ' $form_custom['phone']->getData() . '</p>
  524.                 <p>Email : ' $form_custom['email']->getData() . '</p>
  525.                 <p>Adresse : ' $form_custom['address']->getData() . $form_custom['zipCode']->getData() . $form_custom['city']->getData() . '</p>
  526.                 <p>Message :</p>
  527.                 <p>' $form_custom['message']->getData() . '</p>
  528.                 <br/>
  529.                 <p>Provenance : ' $form_custom['page']->getData() . '</p>
  530.             ';
  531.             $email = (new Email())
  532.                 ->from($configEmail)
  533.                 ->to($configEmail)
  534.                 ->subject('Demande en ligne')
  535.                 ->html($mailbody);
  536.             $this->mailer->send($email);
  537.             $contact = new ContactCustom();
  538.             $contact->setAccountingFirm($this->accountingFirm);
  539.             $contact->setName($form_custom['name']->getData());
  540.             $contact->setEmail($form_custom['email']->getData());
  541.             $contact->setPhone($form_custom['phone']->getData());
  542.             $contact->setAddress($form_custom['address']->getData());
  543.             $contact->setCity($form_custom['city']->getData());
  544.             $contact->setZipCode($form_custom['zipCode']->getData());
  545.             $contact->setMessage($form_custom['message']->getData());
  546.             $contact->setPage($form_custom['page']->getData());
  547.             $contact->setDateadd(new DateTime('now'));
  548.             $this->entityManager->persist($contact);
  549.             $this->entityManager->flush();
  550.             $mailbody_confirm '
  551.                 <p>Bonjour,</p>
  552.                 <p>Votre demande a été envoyée avec succès. Nous allons vous recontacter dans les plus brefs délais. Merci de votre confiance.</p>
  553.                 <p>En soumettant ce formulaire, j\'accepte que les informations saisies soient exploitées dans le cadre de la demande de devis et de la relation commerciale qui peuvent en découler.</p>
  554.             ';
  555.             $email_confirm = (new Email())
  556.                 ->from($configEmail)
  557.                 ->to($form_custom['email']->getData())
  558.                 //->cc('cc@example.com')
  559.                 //->replyTo('fabien@example.com')
  560.                 //->priority(Email::PRIORITY_HIGH)
  561.                 ->subject('Confirmation d\'envoi de votre message')
  562.                 ->html($mailbody_confirm);
  563.             $this->mailer->send($email_confirm);
  564.         }
  565.     }
  566.     public function sendContactProfessionEmail($form_profession)
  567.     {
  568.         $configEmail $this->accountingFirm->getParameters()->getWebMail();
  569.         if (null != $configEmail) {
  570.             $mailbody '
  571.                 <h1>Vous avez reçus une demande de contact depuis votre site web.</h1>
  572.                 <p>Nom : ' $form_profession['name']->getData() . '</p>
  573.                 <p>Téléphone : ' $form_profession['phone']->getData() . '</p>
  574.                 <p>Email : ' $form_profession['email']->getData() . '</p>
  575.                 <p>Profession : ' $form_profession['profession']->getData() . '</p>
  576.                 <p>Message :</p>
  577.                 <p>' $form_profession['message']->getData() . '</p>
  578.                 <br/>
  579.                 <p>Provenance : ' $form_profession['page']->getData() . '</p>
  580.             ';
  581.             $email = (new Email())
  582.                 ->from($configEmail)
  583.                 ->to($configEmail)
  584.                 ->subject('Demande en ligne')
  585.                 ->html($mailbody);
  586.             $this->mailer->send($email);
  587.             $contact = new ContactProfession();
  588.             $contact->setAccountingFirm($this->accountingFirm);
  589.             $contact->setName($form_profession['name']->getData());
  590.             $contact->setEmail($form_profession['email']->getData());
  591.             $contact->setPhone($form_profession['phone']->getData());
  592.             $contact->setProfession($form_profession['profession']->getData());
  593.             $contact->setMessage($form_profession['message']->getData());
  594.             $contact->setPage($form_profession['page']->getData());
  595.             $contact->setDateadd(new DateTime('now'));
  596.             $this->entityManager->persist($contact);
  597.             $this->entityManager->flush();
  598.             $mailbody_confirm '
  599.                 <p>Bonjour,</p>
  600.                 <p>Votre demande a été envoyée avec succès. Nous allons vous recontacter dans les plus brefs délais. Merci de votre confiance.</p>
  601.                 <p>En soumettant ce formulaire, j\'accepte que les informations saisies soient exploitées dans le cadre de la demande de devis et de la relation commerciale qui peuvent en découler.</p>
  602.             ';
  603.             $email_confirm = (new Email())
  604.                 ->from($configEmail)
  605.                 ->to($form_profession['email']->getData())
  606.                 //->cc('cc@example.com')
  607.                 //->replyTo('fabien@example.com')
  608.                 //->priority(Email::PRIORITY_HIGH)
  609.                 ->subject('Confirmation d\'envoi de votre message')
  610.                 ->html($mailbody_confirm);
  611.             $this->mailer->send($email_confirm);
  612.         }
  613.     }
  614.     public function sendContactEtreRappeleEmail($form_etre_rappele)
  615.     {
  616.         $configEmail $this->accountingFirm->getParameters()->getWebMail();
  617.         if (null != $configEmail) {
  618.             $mailbody '
  619.                 <h1>Vous avez reçus une demande de contact Être rappelé depuis votre site web.</h1>
  620.                 <p>Nom : ' $form_etre_rappele['name']->getData() . '</p>
  621.                 <p>Téléphone : ' $form_etre_rappele['phone']->getData() . '</p>
  622.                 <p>Provenance : ' $form_etre_rappele['page']->getData() . '</p>
  623.             ';
  624.             $email = (new Email())
  625.                 ->from($configEmail)
  626.                 ->to($configEmail)
  627.                 ->bcc('tristan.meillat.dev@gmail.com')
  628.                 ->subject('Demande en ligne')
  629.                 ->html($mailbody);
  630.             $this->mailer->send($email);
  631.             $contact = new ContactEtreRappele();
  632.             $contact->setAccountingFirm($this->accountingFirm);
  633.             $contact->setName($form_etre_rappele['name']->getData());
  634.             $contact->setPhone($form_etre_rappele['phone']->getData());
  635.             $contact->setPage($form_etre_rappele['page']->getData());
  636.             $contact->setCreatedAt(new DateTimeImmutable('now'));
  637.             $this->entityManager->persist($contact);
  638.             $this->entityManager->flush();
  639.         }
  640.     }
  641.     public function sendNotifIdentiteVisuelle($mailbody$configEmail$to$subject)
  642.     {
  643.         /*  $contact = $args->getEntity();
  644.           if (!$contact instanceof Contact) {
  645.               return;
  646.           }*/
  647.         if (null != $configEmail) {
  648.             $email = (new Email())
  649.                 ->from(new Address($configEmail'Rudy de lagence.expert'))
  650.                 ->to($to)
  651.                 ->bcc('tristan.meillat28@gmail.com')
  652.                 ->subject($subject)
  653.                 ->html($mailbody);
  654.             $this->mailer->send($email);
  655.         }
  656.     }
  657.     public function sendPreviImmo($contactInvestissementImmo)
  658.     {
  659.         $mailingApi $this->mailjetApiEncryptionService->decryptMailjetApi($this->accountingFirm->getParameters()->getMailjetapi());
  660.         $mailingSender $this->accountingFirm->getParameters()->getWebMail();
  661.         $mj = new Client($mailingApi->getUsername(), $mailingApi->getPassword(), true, ['version' => 'v3.1']);
  662.         $templateParams['datas'] = $contactInvestissementImmo;
  663.         $templateParams['name'] = $this->accountingFirm->getUsers()[0]->getFirstname();
  664.         $template $this->mjmlRenderer->render($this->twig->render('mjml/contact-monprevi-immo/recap.mjml'$templateParams));
  665.         $body = [
  666.             'Messages' => [
  667.                 [
  668.                     'From' => [
  669.                         'Email' => $mailingSender,
  670.                         'Name' => $this->accountingFirm->getName(),
  671.                     ],
  672.                     'To' => [
  673.                         [
  674.                             'Email' => $mailingSender,
  675.                             'Name' => $this->accountingFirm->getName(),
  676.                         ],
  677.                     ],
  678.                     'BCC' => [
  679.                         [
  680.                             'Email' => "tristan.meillat28@gmail.com",
  681.                             'Name' => $this->accountingFirm->getName(),
  682.                         ]
  683.                     ],
  684.                     'Subject' => "Une nouvelle demande de prévisionnel immobilier à été enregistré",
  685.                     'HTMLPart' => $template,
  686.                 ]
  687.             ]
  688.         ];
  689.         $response $mj->post(Resources::$Email, ['body' => $body]);
  690.         $template $this->mjmlRenderer->render($this->twig->render('mjml/contact-monprevi-immo/confirmation.mjml'$templateParams));
  691.         $body = [
  692.             'Messages' => [
  693.                 [
  694.                     'From' => [
  695.                         'Email' => $mailingSender,
  696.                         'Name' => $this->accountingFirm->getName(),
  697.                     ],
  698.                     'To' => [
  699.                         [
  700.                             'Email' => $contactInvestissementImmo->getEmail(),
  701.                             'Name' => $contactInvestissementImmo->getFirstname() . ' ' $contactInvestissementImmo->getName(),
  702.                         ]
  703.                     ],
  704.                     'Subject' => "Confirmation de votre commande – Prévisionnel MonPrevi.fr",
  705.                     'HTMLPart' => $template,
  706.                 ]
  707.             ]
  708.         ];
  709.         $response $mj->post(Resources::$Email, ['body' => $body]);
  710.     }
  711.     public function sendPreviCreation($contactPreviCreation)
  712.     {
  713.         $mailingApi $this->mailjetApiEncryptionService->decryptMailjetApi($this->accountingFirm->getParameters()->getMailjetapi());
  714.         $receiver $this->accountingFirm->getParameters()->getWebMail();
  715.         if ($this->accountingFirm->getId() == 320) {
  716.             $receiver "tristan.meillat28@gmail.com";
  717.         }
  718.         $mailingSender $this->accountingFirm->getParameters()->getWebMail();
  719.         $mj = new Client($mailingApi->getUsername(), $mailingApi->getPassword(), true, ['version' => 'v3.1']);
  720.         $templateParams['datas'] = $contactPreviCreation;
  721.         $templateParams['name'] = $this->accountingFirm->getUsers()[0]->getFirstname();
  722.         $template $this->mjmlRenderer->render($this->twig->render('mjml/contact-monprevi-creation/recap.mjml'$templateParams));
  723.         $body = [
  724.             'Messages' => [
  725.                 [
  726.                     'From' => [
  727.                         'Email' => $mailingSender,
  728.                         'Name' => $this->accountingFirm->getName(),
  729.                     ],
  730.                     'To' => [
  731.                         [
  732.                             'Email' => $receiver,
  733.                             'Name' => $this->accountingFirm->getName(),
  734.                         ],
  735.                     ],
  736.                     'BCC' => [
  737.                         [
  738.                             'Email' => "tristan.meillat28@gmail.com",
  739.                             'Name' => $this->accountingFirm->getName(),
  740.                         ]
  741.                     ],
  742.                     'Subject' => "Une nouvelle demande de "$contactPreviCreation->getCategory() ." est arrivée !",
  743.                     'HTMLPart' => $template,
  744.                 ]
  745.             ]
  746.         ];
  747.         $response $mj->post(Resources::$Email, ['body' => $body]);
  748.         $template $this->mjmlRenderer->render($this->twig->render('mjml/contact-monprevi-creation/confirmation.mjml'$templateParams));
  749.         $body = [
  750.             'Messages' => [
  751.                 [
  752.                     'From' => [
  753.                         'Email' => $mailingSender,
  754.                         'Name' => $this->accountingFirm->getName(),
  755.                     ],
  756.                     'To' => [
  757.                         [
  758.                             'Email' => $contactPreviCreation->getEmail(),
  759.                             'Name' => $contactPreviCreation->getFirstname() . ' ' $contactPreviCreation->getName(),
  760.                         ]
  761.                     ],
  762.                     'Subject' => "Votre demande de "$contactPreviCreation->getCategory() ." a bien été enregistré !",
  763.                     'HTMLPart' => $template,
  764.                 ]
  765.             ]
  766.         ];
  767.         $response $mj->post(Resources::$Email, ['body' => $body]);
  768.     }
  769.     public function sendNotifCollaborateur(array $templateParamsstring $tostring $subject, ?string $toName null, ?AccountingFirm $firm null)
  770.     {
  771.         $mailjetApi $firm $firm->getMailingApi() : null;
  772.         if (!$mailjetApi) {
  773.             $mailjetApi $this->getInternalMailjetApi();
  774.         }
  775.         if ($mailjetApi) {
  776.             $this->initMailjet($mailjetApi);
  777.             $mjml $this->twig->render('mjml/notifications/collaborateur_access.mjml'$templateParams);
  778.             $html $this->mjmlRenderer->render($mjml);
  779.             $fromEmail 'rudy@lagence.expert';
  780.             $fromName 'Rudy de lagence.expert';
  781.             if ($firm && $firm->getMailingSender()) {
  782.                 $fromEmail $firm->getMailingSender();
  783.                 $fromName $firm->getName();
  784.             }
  785.             return $this->sendMailjet(
  786.                 from: ['Email' => $fromEmail'Name' => $fromName],
  787.                 to: [['Email' => $to'Name' => $toName]],
  788.                 subject$subject,
  789.                 htmlPart$html
  790.             );
  791.         }
  792.         return null;
  793.     }
  794. }