<?php
namespace App\Services;
use App\Entity\AccountingFirm;
use App\Entity\Announcement;
use App\Entity\ApplyRequest;
use App\Entity\Contact;
use App\Entity\ContactCustom;
use App\Entity\ContactEtreRappele;
use App\Entity\ContactInvestissementImmoProperty;
use App\Entity\ContactInvestissementImmoPropertyCharge;
use App\Entity\ContactPipelineStep;
use App\Entity\ContactProfession;
use App\Entity\ContactSubjectType;
use App\Entity\DemandeCompany;
use App\Entity\DemandeNewsletter;
use App\Entity\Ebook;
use App\Entity\MailjetApi;
use App\Entity\Prescriber;
use App\Repository\AccountingFirmRepository;
use DateTime;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;
use Mailjet\Client;
use Mailjet\Resources;
use Qferrer\Mjml\Twig\MjmlExtension;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Twig\Environment;
class SendContactEmail
{
protected $entityManager;
protected $requestStack;
protected $mailjetApiEncryptionService;
protected MjmlExtension $mjmlRenderer;
protected Environment $twig;
private $accountingFirm;
private $mailer;
private $mailjet_username;
private $mailjet_password;
private ?Client $mj = null;
public function __construct(CustomMailer $mailer, AccountingFirmRepository $accountingFirmRepository, EntityManagerInterface $entityManager, RequestStack $requestStack, MailjetApiEncryptionService $mailjetApiEncryptionService, MjmlExtension $mjmlRenderer, Environment $twig)
{
$this->entityManager = $entityManager;
$this->requestStack = $requestStack;
$this->mailjetApiEncryptionService = $mailjetApiEncryptionService;
$this->mjmlRenderer = $mjmlRenderer;
$this->twig = $twig;
$theHost = Request::createFromGlobals()->getHost();
$theHost = str_replace('www.', '', $theHost);
$this->theHost = $theHost;
if (preg_match('/preview/', $this->requestStack->getCurrentRequest()->get('_route'))) {
$theHost = $this->requestStack->getCurrentRequest()->attributes->get('host');
}
$this->accountingFirm = $accountingFirmRepository->findOneBy([
'host' => $theHost
]);
if ($this->accountingFirm != null && $this->accountingFirm->getParameters()->getMailjetapi() != null) {
$mailjetApi = $this->mailjetApiEncryptionService->decryptMailjetApi($this->accountingFirm->getParameters()->getMailjetapi());
$this->mailjet_username = $mailjetApi->getUsername();
$this->mailjet_password = $mailjetApi->getPassword();
$this->mailer = $mailer->getMailer($this->mailjet_username, $this->mailjet_password);
} else {
$mailjetApiRepository = $this->entityManager->getRepository(MailjetApi::class);
$mailjetApi = $this->mailjetApiEncryptionService->decryptMailjetApi($mailjetApiRepository->findOneBy(['id' => 1]));
$this->mailer = $mailer->getMailer($mailjetApi->getUsername(), $mailjetApi->getPassword());
}
if ($this->requestStack->getCurrentRequest()->get('_route') == "identite_visuelle_edit") {
$mailjetApiRepository = $this->entityManager->getRepository(MailjetApi::class);
$mailjetApi = $this->mailjetApiEncryptionService->decryptMailjetApi($mailjetApiRepository->findOneBy(['id' => 2]));
$this->mailer = $mailer->getMailer($mailjetApi->getUsername(), $mailjetApi->getPassword());
}
$this->mailjetApiEncryptionService = $mailjetApiEncryptionService;
}
private function initMailjet(?MailjetApi $mailjetApi): void
{
if (!$mailjetApi) {
throw new \RuntimeException('Missing Mailjet API credentials');
}
$decrypted = $this->mailjetApiEncryptionService->decryptMailjetApi($mailjetApi);
$this->mj = new Client(
$decrypted->getUsername(),
$decrypted->getPassword(),
true,
['version' => 'v3.1']
);
}
private function sendMailjet(
array $from,
array $to,
string $subject,
string $htmlPart,
?array $cc = null
): ?string {
if (!$this->mj) {
return "NO_MAILJET_CLIENT";
}
$message = [
'From' => $from,
'To' => $to,
'Subject' => $subject,
'HTMLPart' => $htmlPart,
];
if ($cc) {
$message['Cc'] = $cc;
}
$body = ['Messages' => [$message]];
try {
$response = $this->mj->post(Resources::$Email, ['body' => $body]);
if ($response->success()) {
return "SEND";
}
return "ERROR_SENDING";
} catch (\Throwable $e) {
return "ERROR_SENDING";
}
}
private function getInternalMailjetApi(): ?MailjetApi
{
return $this->entityManager->getRepository(MailjetApi::class)->findOneBy(['id' => 1]);
}
public function sendContactEmail($form)
{
$configEmail = $this->accountingFirm->getParameters()->getWebMail();
if (null != $configEmail) {
$mailbody = '
<h1>Vous avez reçus une demande de contact depuis votre site web.</h1>
<p>Sujet : ' . $form['subjectType']->getData() . '</p>
<p>Nom : ' . $form['name']->getData() . '</p>
<p>Téléphone : ' . $form['phone']->getData() . '</p>
<p>Email : ' . $form['email']->getData() . '</p>
<p>Message :</p>
<p>' . $form['message']->getData() . '</p>
<br/>
<p>Provenance : ' . $form['page']->getData() . '</p>
';
$email = (new Email())
->from($configEmail)
->to($configEmail)
->subject('Demande en ligne')
->html($mailbody);
$this->mailer->send($email);
$contact = new Contact();
$contact->setAccountingFirm($this->accountingFirm);
$contact->setSubjectType($form['subjectType']->getData());
$contact->setName($form['name']->getData());
$contact->setEmail($form['email']->getData());
$contact->setPhone($form['phone']->getData());
$contact->setMessage($form['message']->getData());
$contact->setPage($form['page']->getData());
$contact->setDateadd(new DateTime('now'));
if ($form['subjectType']->getData()->getSlug() === ContactSubjectType::PROSPECT || $form['subjectType']->getData()->getSlug() === ContactSubjectType::DEMANDE_DEVISE) {
$contact->setCurrentStep($this->entityManager->getRepository(ContactPipelineStep::class)->findOneByPosition(1));
}
$this->entityManager->persist($contact);
$this->entityManager->flush();
$mailbody_confirm = '
<p>Bonjour,</p>
<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>
<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>
';
$email_confirm = (new Email())
->from($configEmail)
->to($form['email']->getData())
//->cc('cc@example.com')
//->replyTo('fabien@example.com')
//->priority(Email::PRIORITY_HIGH)
->subject('Confirmation d\'envoi de votre message')
->html($mailbody_confirm);
$this->mailer->send($email_confirm);
if ($form['route']->getData() == "previewprescripteur_client" || $form['route']->getData() == "prescripteur_client") {
$idPrescriber = $form['id_prescriber']->getData();
$contactPrescriber = $this->entityManager->getRepository(Prescriber::class)->findOneBy(['id' => $idPrescriber]);
if ($contactPrescriber) {
$mailbody_prescriber = '
<p>Bonjour,</p>
<p>Une demande vient d’être déposée sur le site du <strong>Propuls’Cab</strong> suite à votre recommandation.</p>
<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>
<p>Merci pour votre confiance.</p>
<p>
-- <br>
Bien cordialement, <br>
<strong>Joseph MISRAHI</strong> <br>
<strong>Expert-comptable Associé du cabinet Propuls’cab</strong> <br>
</p>
';
$email_prescriber = (new Email())
->from($configEmail)
->to($contactPrescriber->getMail())
//->cc('cc@example.com')
->bcc('tristan.meillat28@gmail.com')
//->replyTo('fabien@example.com')
//->priority(Email::PRIORITY_HIGH)
->subject('Nouvelle demande reçue via Propuls’Cab')
->html($mailbody_prescriber);
}
$this->mailer->send($email_prescriber);
}
}
}
public function sendRecrutementEmail($form)
{
$configEmail = $this->accountingFirm->getParameters()->getWebMail();
$contact = new ApplyRequest();
$filesystem = new Filesystem();
$cv = $form['tmpCV']->getData();
$lm = $form['tmpLettre']->getData();
if ($cv) {
$directory = '../public/cvs/';
try {
if (!$filesystem->exists($directory)) {
$filesystem->mkdir($directory);
}
$originalFilename = pathinfo($cv->getClientOriginalName(), PATHINFO_FILENAME);
$fileNamecv = $originalFilename . '-' . uniqid() . '.' . $cv->guessExtension();
$cv->move($directory, $fileNamecv);
$contact->setCv($fileNamecv);
} catch (FileException $e) {
}
}
if ($lm) {
$directory = '../public/lms/';
try {
if (!$filesystem->exists($directory)) {
$filesystem->mkdir($directory);
}
$originalFilename = pathinfo($lm->getClientOriginalName(), PATHINFO_FILENAME);
$fileNamelm = $originalFilename . '-' . uniqid() . '.' . $lm->guessExtension();
$lm->move($directory, $fileNamelm);
$contact->setLettre($fileNamelm);
} catch (FileException $e) {
}
}
if (null != $configEmail) {
$mailbody = '
<h1>Vous avez reçus une réponse à votre annonce de recrutement depuis votre site web.</h1>
<p>Nom : ' . $form['nom']->getData() . '</p>
<p>Téléphone : ' . $form['tel']->getData() . '</p>
<p>Email : ' . $form['email']->getData() . '</p>
<p>Message :</p>
<p>' . $form['message']->getData() . '</p>
<br/>
';
if ($fileNamecv and !$fileNamelm) {
$email = (new Email())
->from($configEmail)
->to($configEmail)
->subject('Demande en ligne')
->html($mailbody)
->attach(fopen("../public/cvs/" . $fileNamecv, 'r'), $fileNamecv);
} elseif (!$fileNamecv and $fileNamelm) {
$email = (new Email())
->from($configEmail)
->to($configEmail)
->subject('Demande en ligne')
->html($mailbody)
->attach(fopen("../public/lms/" . $fileNamelm, 'r'), $fileNamelm);
} elseif (!$fileNamecv and !$fileNamelm) {
$email = (new Email())
->from($configEmail)
->to($configEmail)
->subject('Demande en ligne')
->html($mailbody);
} else { // lm and cv defined
$email = (new Email())
->from($configEmail)
->to($configEmail)
->subject('Demande en ligne')
->html($mailbody)
->attach(fopen("../public/cvs/" . $fileNamecv, 'r'), $fileNamecv)
->attach(fopen("../public/lms/" . $fileNamelm, 'r'), $fileNamelm);
}
$this->mailer->send($email);
$contact->setDate(new DateTime('now'));
$contact->setNom($form['nom']->getData());
$contact->setEmail($form['email']->getData());
$contact->setTel($form['tel']->getData());
$contact->setMessage($form['message']->getData());
//$contact->setCv($form['cv']->getData());
//$contact->setLettre($form['lettre']->getData());
$contact->setRgpd($form['rgpd']->getData());
$annonceRepo = $this->entityManager->getRepository(Announcement::class);
$annonce = $annonceRepo->findOneBy(['id' => $form['announcementId']->getData()]);
$contact->setAnnonce($annonce);
$this->entityManager->persist($contact);
$this->entityManager->flush();
$mailbody_confirm = '
<p>Bonjour,</p>
<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>
<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>
';
$email_confirm = (new Email())
->from($configEmail)
->to($form['email']->getData())
//->cc('cc@example.com')
//->replyTo('fabien@example.com')
//->priority(Email::PRIORITY_HIGH)
->subject('Confirmation d\'envoi de votre message')
->html($mailbody_confirm);
$this->mailer->send($email_confirm);
}
}
public function sendEbookEmail($form_livre)
{
$ebookData = $this->entityManager->getRepository(Ebook::class)->findOneBy(['id' => $form_livre['ebookId']->getData()]);
if (!is_null($ebookData)) {
$configEmail = $this->accountingFirm->getParameters()->getWebMail();
if (null != $configEmail) {
$mailbody = '
<h1>Quelqu\'un a téléchargé un livre blanc :</h1>
<p>Nom : ' . $form_livre['surname']->getData() . '</p>
<p>Prénom : ' . $form_livre['name']->getData() . '</p>
<p>Société : ' . $form_livre['company']->getData() . '</p>
<p>Fonction : ' . $form_livre['function']->getData() . '</p>
<p>Adresse : ' . $form_livre['adress']->getData() . '</p>
<p>Activité : ' . $form_livre['activity']->getData() . '</p>
<p>Téléphone : ' . $form_livre['phone']->getData() . '</p>
<p>Email : ' . $form_livre['email']->getData() . '</p>
<br/>
<p>Livre blanc : ' . $form_livre['ebookId']->getData() . ' | ' . $ebookData->getTitle() . '</p>
<p>Provenance : ' . $form_livre['page']->getData() . '</p>
';
$email = (new Email())
->from($configEmail)
->to($configEmail)
//->cc('cc@example.com')
->subject('Téléchargement d\'un livre blanc')
->html($mailbody);
$this->mailer->send($email);
$mailbody_confirm = "
<p>Bonjour</p>
<br><br>
<p>Nous avons le plaisir de vous envoyer ce livre blanc " . $ebookData->getTitle() . ",
nous vous invitons à le télécharger à partir de ce lien : <a target=\"_blank\" href=\"https://" . $this->theHost . '/medias/documents/' . $ebookData->getDocuments()->first()->getName() . "\">Télécharger</a>
</p><br>
<p>Bonne lecture,<br>L'équipe " . $this->accountingFirm->getName() . ".</p>
";
$email_confirm = (new Email())
->from($configEmail)
->to($form_livre['email']->getData())
//->cc('cc@example.com')
//->replyTo('fabien@example.com')
//->priority(Email::PRIORITY_HIGH)
->subject('Confirmation d\'envoi de votre message')
->html($mailbody_confirm);
$this->mailer->send($email_confirm);
}
} else {
//die('🐛 SPAM !');
}
}
public function sendCompanyEmail($form_company)
{
$configEmail = $this->accountingFirm->getParameters()->getWebMail();
if (null != $configEmail) {
$mailbody = '
<h1>Demande de création d\'entreprise :</h1>
<p>Forme juridique retenue : ' . $form_company['formeJuridique']->getData() . '</p>
<p>Capital social : ' . $form_company['capital']->getData() . '</p>
<p>Nature de l\'activité : ' . $form_company['activite']->getData() . '</p>
<p>Date de début d\'activité : ' . $form_company['dateDebutActivite']->getData()->format('Y-m-d') . '</p>
<p>Nombre d\'associés : ' . $form_company['nbAssocie']->getData() . '</p>
<p>Nombre d\'actions : ' . $form_company['nbAction']->getData() . '</p>
<p>Valeur nominale des actions : ' . $form_company['valeurAction']->getData() . '</p>
<p>Nom : ' . $form_company['name']->getData() . '</p>
<p>Prénom : ' . $form_company['surname']->getData() . '</p>
<p>Téléphone : ' . $form_company['phone']->getData() . '</p>
<p>Email : ' . $form_company['email']->getData() . '</p>
<br/>
';
$email = (new Email())
->from($configEmail)
->to($configEmail)
//->cc('cc@example.com')
//->replyTo('fabien@example.com')
//->priority(Email::PRIORITY_HIGH)
->subject('Demande de création d\'entreprise')
->html($mailbody);
$this->mailer->send($email);
$company = new DemandeCompany();
$company->setAccountingFirm($this->accountingFirm);
$company->setFormeJuridique($form_company['formeJuridique']->getData());
$company->setCapital($form_company['capital']->getData());
$company->setActivite($form_company['activite']->getData());
$company->setDateDebutActivite($form_company['dateDebutActivite']->getData());
$company->setNbAction($form_company['nbAction']->getData());
$company->setNbAssocie($form_company['nbAssocie']->getData());
$company->setValeurAction($form_company['valeurAction']->getData());
$company->setSurname($form_company['surname']->getData());
$company->setPhone($form_company['phone']->getData());
$company->setPage($form_company['page']->getData());
$company->setRgpd($form_company['rgpd']->getData());
$company->setName($form_company['name']->getData());
$company->setEmail($form_company['email']->getData());
$company->setDateadd(new DateTime('now'));
$this->entityManager->persist($company);
$this->entityManager->flush();
$mailbody_confirm = "
<p>Bonjour</p>
<br><br>
<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>
<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'équipe " . $this->accountingFirm->getName() . ".</p>
";
$email_confirm = (new Email())
->from($configEmail)
->to($form_company['email']->getData())
//->cc('cc@example.com')
//->replyTo('fabien@example.com')
//->priority(Email::PRIORITY_HIGH)
->subject('Confirmation d\'envoi de votre message')
->html($mailbody_confirm);
$this->mailer->send($email_confirm);
}
}
public function sendMiniEbookEmail($form_minibook)
{
if (empty(trim($form_minibook['hp']->getData()))) {
$configEmail = $this->accountingFirm->getParameters()->getWebMail();
if (null != $configEmail) {
$mailbody = '
<h3>Nouvelle demande de livre blanc : </h3>
<p><strong>Nom :</strong> ' . $form_minibook['name']->getData() . '</p>
<p><strong>Email :</strong> ' . $form_minibook['email']->getData() . '</p>
';
$email = (new Email())
->from($configEmail)
->to($configEmail)
//->cc('cc@example.com')
//->replyTo('fabien@example.com')
//->priority(Email::PRIORITY_HIGH)
->subject('Demande livre blanc')
->html($mailbody);
// $this->mailer->send($email);
$this->form_send_minibook = true;
$mailbody_confirm = '
<p>Bonjour,</p>
<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>
';
$email_confirm = (new Email())
->from($configEmail)
->to($form_minibook['email']->getData())
//->cc('cc@example.com')
//->replyTo('fabien@example.com')
//->priority(Email::PRIORITY_HIGH)
->subject('Demande livre blanc')
->html($mailbody_confirm);
//$this->mailer->send($email_confirm);
}
} else {
//die('🐛 SPAM !');
}
}
public function sendNewsletterEmail($form_newsletter)
{
if (empty(trim($form_newsletter['hp']->getData()))) {
$configEmail = $this->accountingFirm->getParameters()->getWebMail();
if (null != $configEmail) {
$mailbody = '
<h1>Vous avez reçus une demande de d\'inscription newsletter depuis votre site web.</h1>
<p>Nom : ' . $form_newsletter['name']->getData() . '</p>
<p>Email : ' . $form_newsletter['email']->getData() . '</p>
';
$email = (new Email())
->from($configEmail)
->to($configEmail)
//->cc('cc@example.com')
//->replyTo('fabien@example.com')
//->priority(Email::PRIORITY_HIGH)
->subject('Demande inscription newsletter')
->html($mailbody);
$this->mailer->send($email);
$newletter = new DemandeNewsletter();
$newletter->setAccountingFirm($this->accountingFirm);
$newletter->setName($form_newsletter['name']->getData());
$newletter->setEmail($form_newsletter['email']->getData());
$newletter->setDateadd(new DateTime('now'));
$this->entityManager->persist($newletter);
$this->entityManager->flush();
$mailbody_confirm = '
<p>Bonjour,</p>
<p>Votre inscription à notre newsletter a bien été enregistrée. </p>
';
$email_confirm = (new Email())
->from($configEmail)
->to($form_newsletter['email']->getData())
//->cc('cc@example.com')
//->replyTo('fabien@example.com')
//->priority(Email::PRIORITY_HIGH)
->subject('Confirmation d\'inscription newsletter')
->html($mailbody_confirm);
$this->mailer->send($email_confirm);
}
} else {
//die('🐛 SPAM !');
}
}
public function sendEmail($mailbody, $to, $subject)
{
/* $contact = $args->getEntity();
if (!$contact instanceof Contact) {
return;
}*/
$configEmail = $this->accountingFirm->getParameters()->getWebMail();
if (null != $configEmail) {
$email = (new Email())
->from($configEmail)
->to($to)
->subject($subject)
->html($mailbody);
$this->mailer->send($email);
}
}
public function sendContactCustomEmail($form_custom)
{
$configEmail = $this->accountingFirm->getParameters()->getWebMail();
if (null != $configEmail) {
$mailbody = '
<h1>Vous avez reçus une demande de contact depuis votre site web.</h1>
<p>Nom : ' . $form_custom['name']->getData() . '</p>
<p>Téléphone : ' . $form_custom['phone']->getData() . '</p>
<p>Email : ' . $form_custom['email']->getData() . '</p>
<p>Adresse : ' . $form_custom['address']->getData() . $form_custom['zipCode']->getData() . $form_custom['city']->getData() . '</p>
<p>Message :</p>
<p>' . $form_custom['message']->getData() . '</p>
<br/>
<p>Provenance : ' . $form_custom['page']->getData() . '</p>
';
$email = (new Email())
->from($configEmail)
->to($configEmail)
->subject('Demande en ligne')
->html($mailbody);
$this->mailer->send($email);
$contact = new ContactCustom();
$contact->setAccountingFirm($this->accountingFirm);
$contact->setName($form_custom['name']->getData());
$contact->setEmail($form_custom['email']->getData());
$contact->setPhone($form_custom['phone']->getData());
$contact->setAddress($form_custom['address']->getData());
$contact->setCity($form_custom['city']->getData());
$contact->setZipCode($form_custom['zipCode']->getData());
$contact->setMessage($form_custom['message']->getData());
$contact->setPage($form_custom['page']->getData());
$contact->setDateadd(new DateTime('now'));
$this->entityManager->persist($contact);
$this->entityManager->flush();
$mailbody_confirm = '
<p>Bonjour,</p>
<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>
<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>
';
$email_confirm = (new Email())
->from($configEmail)
->to($form_custom['email']->getData())
//->cc('cc@example.com')
//->replyTo('fabien@example.com')
//->priority(Email::PRIORITY_HIGH)
->subject('Confirmation d\'envoi de votre message')
->html($mailbody_confirm);
$this->mailer->send($email_confirm);
}
}
public function sendContactProfessionEmail($form_profession)
{
$configEmail = $this->accountingFirm->getParameters()->getWebMail();
if (null != $configEmail) {
$mailbody = '
<h1>Vous avez reçus une demande de contact depuis votre site web.</h1>
<p>Nom : ' . $form_profession['name']->getData() . '</p>
<p>Téléphone : ' . $form_profession['phone']->getData() . '</p>
<p>Email : ' . $form_profession['email']->getData() . '</p>
<p>Profession : ' . $form_profession['profession']->getData() . '</p>
<p>Message :</p>
<p>' . $form_profession['message']->getData() . '</p>
<br/>
<p>Provenance : ' . $form_profession['page']->getData() . '</p>
';
$email = (new Email())
->from($configEmail)
->to($configEmail)
->subject('Demande en ligne')
->html($mailbody);
$this->mailer->send($email);
$contact = new ContactProfession();
$contact->setAccountingFirm($this->accountingFirm);
$contact->setName($form_profession['name']->getData());
$contact->setEmail($form_profession['email']->getData());
$contact->setPhone($form_profession['phone']->getData());
$contact->setProfession($form_profession['profession']->getData());
$contact->setMessage($form_profession['message']->getData());
$contact->setPage($form_profession['page']->getData());
$contact->setDateadd(new DateTime('now'));
$this->entityManager->persist($contact);
$this->entityManager->flush();
$mailbody_confirm = '
<p>Bonjour,</p>
<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>
<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>
';
$email_confirm = (new Email())
->from($configEmail)
->to($form_profession['email']->getData())
//->cc('cc@example.com')
//->replyTo('fabien@example.com')
//->priority(Email::PRIORITY_HIGH)
->subject('Confirmation d\'envoi de votre message')
->html($mailbody_confirm);
$this->mailer->send($email_confirm);
}
}
public function sendContactEtreRappeleEmail($form_etre_rappele)
{
$configEmail = $this->accountingFirm->getParameters()->getWebMail();
if (null != $configEmail) {
$mailbody = '
<h1>Vous avez reçus une demande de contact Être rappelé depuis votre site web.</h1>
<p>Nom : ' . $form_etre_rappele['name']->getData() . '</p>
<p>Téléphone : ' . $form_etre_rappele['phone']->getData() . '</p>
<p>Provenance : ' . $form_etre_rappele['page']->getData() . '</p>
';
$email = (new Email())
->from($configEmail)
->to($configEmail)
->bcc('tristan.meillat.dev@gmail.com')
->subject('Demande en ligne')
->html($mailbody);
$this->mailer->send($email);
$contact = new ContactEtreRappele();
$contact->setAccountingFirm($this->accountingFirm);
$contact->setName($form_etre_rappele['name']->getData());
$contact->setPhone($form_etre_rappele['phone']->getData());
$contact->setPage($form_etre_rappele['page']->getData());
$contact->setCreatedAt(new DateTimeImmutable('now'));
$this->entityManager->persist($contact);
$this->entityManager->flush();
}
}
public function sendNotifIdentiteVisuelle($mailbody, $configEmail, $to, $subject)
{
/* $contact = $args->getEntity();
if (!$contact instanceof Contact) {
return;
}*/
if (null != $configEmail) {
$email = (new Email())
->from(new Address($configEmail, 'Rudy de lagence.expert'))
->to($to)
->bcc('tristan.meillat28@gmail.com')
->subject($subject)
->html($mailbody);
$this->mailer->send($email);
}
}
public function sendPreviImmo($contactInvestissementImmo)
{
$mailingApi = $this->mailjetApiEncryptionService->decryptMailjetApi($this->accountingFirm->getParameters()->getMailjetapi());
$mailingSender = $this->accountingFirm->getParameters()->getWebMail();
$mj = new Client($mailingApi->getUsername(), $mailingApi->getPassword(), true, ['version' => 'v3.1']);
$templateParams['datas'] = $contactInvestissementImmo;
$templateParams['name'] = $this->accountingFirm->getUsers()[0]->getFirstname();
$template = $this->mjmlRenderer->render($this->twig->render('mjml/contact-monprevi-immo/recap.mjml', $templateParams));
$body = [
'Messages' => [
[
'From' => [
'Email' => $mailingSender,
'Name' => $this->accountingFirm->getName(),
],
'To' => [
[
'Email' => $mailingSender,
'Name' => $this->accountingFirm->getName(),
],
],
'BCC' => [
[
'Email' => "tristan.meillat28@gmail.com",
'Name' => $this->accountingFirm->getName(),
]
],
'Subject' => "Une nouvelle demande de prévisionnel immobilier à été enregistré",
'HTMLPart' => $template,
]
]
];
$response = $mj->post(Resources::$Email, ['body' => $body]);
$template = $this->mjmlRenderer->render($this->twig->render('mjml/contact-monprevi-immo/confirmation.mjml', $templateParams));
$body = [
'Messages' => [
[
'From' => [
'Email' => $mailingSender,
'Name' => $this->accountingFirm->getName(),
],
'To' => [
[
'Email' => $contactInvestissementImmo->getEmail(),
'Name' => $contactInvestissementImmo->getFirstname() . ' ' . $contactInvestissementImmo->getName(),
]
],
'Subject' => "Confirmation de votre commande – Prévisionnel MonPrevi.fr",
'HTMLPart' => $template,
]
]
];
$response = $mj->post(Resources::$Email, ['body' => $body]);
}
public function sendPreviCreation($contactPreviCreation)
{
$mailingApi = $this->mailjetApiEncryptionService->decryptMailjetApi($this->accountingFirm->getParameters()->getMailjetapi());
$receiver = $this->accountingFirm->getParameters()->getWebMail();
if ($this->accountingFirm->getId() == 320) {
$receiver = "tristan.meillat28@gmail.com";
}
$mailingSender = $this->accountingFirm->getParameters()->getWebMail();
$mj = new Client($mailingApi->getUsername(), $mailingApi->getPassword(), true, ['version' => 'v3.1']);
$templateParams['datas'] = $contactPreviCreation;
$templateParams['name'] = $this->accountingFirm->getUsers()[0]->getFirstname();
$template = $this->mjmlRenderer->render($this->twig->render('mjml/contact-monprevi-creation/recap.mjml', $templateParams));
$body = [
'Messages' => [
[
'From' => [
'Email' => $mailingSender,
'Name' => $this->accountingFirm->getName(),
],
'To' => [
[
'Email' => $receiver,
'Name' => $this->accountingFirm->getName(),
],
],
'BCC' => [
[
'Email' => "tristan.meillat28@gmail.com",
'Name' => $this->accountingFirm->getName(),
]
],
'Subject' => "Une nouvelle demande de ". $contactPreviCreation->getCategory() ." est arrivée !",
'HTMLPart' => $template,
]
]
];
$response = $mj->post(Resources::$Email, ['body' => $body]);
$template = $this->mjmlRenderer->render($this->twig->render('mjml/contact-monprevi-creation/confirmation.mjml', $templateParams));
$body = [
'Messages' => [
[
'From' => [
'Email' => $mailingSender,
'Name' => $this->accountingFirm->getName(),
],
'To' => [
[
'Email' => $contactPreviCreation->getEmail(),
'Name' => $contactPreviCreation->getFirstname() . ' ' . $contactPreviCreation->getName(),
]
],
'Subject' => "Votre demande de ". $contactPreviCreation->getCategory() ." a bien été enregistré !",
'HTMLPart' => $template,
]
]
];
$response = $mj->post(Resources::$Email, ['body' => $body]);
}
public function sendNotifCollaborateur(array $templateParams, string $to, string $subject, ?string $toName = null, ?AccountingFirm $firm = null)
{
$mailjetApi = $firm ? $firm->getMailingApi() : null;
if (!$mailjetApi) {
$mailjetApi = $this->getInternalMailjetApi();
}
if ($mailjetApi) {
$this->initMailjet($mailjetApi);
$mjml = $this->twig->render('mjml/notifications/collaborateur_access.mjml', $templateParams);
$html = $this->mjmlRenderer->render($mjml);
$fromEmail = 'rudy@lagence.expert';
$fromName = 'Rudy de lagence.expert';
if ($firm && $firm->getMailingSender()) {
$fromEmail = $firm->getMailingSender();
$fromName = $firm->getName();
}
return $this->sendMailjet(
from: ['Email' => $fromEmail, 'Name' => $fromName],
to: [['Email' => $to, 'Name' => $toName]],
subject: $subject,
htmlPart: $html
);
}
return null;
}
}