src/Services/SendContactEmail.php line 50

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