src/Services/MailerServices.php line 121

Open in your IDE?
  1. <?php
  2. namespace App\Services;
  3. use Mailjet\Client;
  4. use Mailjet\Resources;
  5. use Symfony\Component\Mime\Email;
  6. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  7. use Symfony\Component\Mailer\MailerInterface;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Mailer\Exception\TransportException;
  10. use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
  11. class MailerServices
  12. {
  13.     public function sendEmail(MailerInterface $mailer$from$to$name_to$subject$template)
  14.     {
  15.         try {
  16.             $email = (new TemplatedEmail())
  17.                 ->from($from)
  18.                 ->to($to)
  19.                 ->subject($subject)
  20.                 ->htmlTemplate($template)
  21.                 ->context([
  22.                     'name' => $name_to
  23.                 ]);
  24.             $mailer->send($email);
  25.         } catch (\Exception $e) {
  26.             return false;
  27.         }
  28.     }
  29.     public function sendMail(MailerInterface $mailer$to$from$subject$template$params)
  30.     {
  31.         try {
  32.             /*Test*/
  33.             /* $from = "commande@ictuspharma.com";
  34.             $to = "zoanja@yahoo.fr"; */
  35.             /*Test*/
  36.             $email = (new TemplatedEmail())
  37.                 ->from($from)
  38.                 ->to($to)
  39.                 ->subject($subject)
  40.                 ->htmlTemplate($template)
  41.                 ->context($params);
  42.             $mailer->send($email);
  43.         } catch (TransportException $e) {
  44.             return null;
  45.         }
  46.     }
  47.     public function send(MailerInterface $mailer$to$from$subject$template$params)
  48.     {
  49.         try {
  50.             /*Test*/
  51.             /* $from = "commande@ictuspharma.com";
  52.             $to = "zoanja@yahoo.fr"; */
  53.             /*Test*/
  54.             $email = (new TemplatedEmail())
  55.                 ->from($from)
  56.                 ->to($to)
  57.                 ->subject($subject)
  58.                 ->htmlTemplate($template)
  59.                 ->context($params);
  60.             $mailer->send($email);
  61.         } catch (TransportException $e) {
  62.             return null;
  63.         }
  64.     }
  65.     public function sendWithCc(MailerInterface $mailer$to$cc$from$subject$template$params)
  66.     {
  67.         try {
  68.             /*Test*/
  69.             /* $from = "commande@ictuspharma.com";
  70.             $to = "zoanja@yahoo.fr"; */
  71.             /*Test*/
  72.             $email = (new TemplatedEmail())
  73.                 ->from($from)
  74.                 ->to($to)
  75.                 ->cc($cc)
  76.                 ->subject($subject)
  77.                 ->htmlTemplate($template)
  78.                 ->context($params);
  79.             $mailer->send($email);
  80.         } catch (TransportException $e) {
  81.             return null;
  82.         }
  83.     }
  84.     public function sendEmailAdmin(MailerInterface $mailer$from$to$name_client$id_client$subject$template)
  85.     {
  86.         $email = (new TemplatedEmail())
  87.             ->from($from)
  88.             ->to($to)
  89.             ->subject($subject)
  90.             ->htmlTemplate($template)
  91.             ->context([
  92.                 'name' => $name_client,
  93.                 'id_client' => $id_client
  94.             ]);
  95.         $mailer->send($email);
  96.     }
  97.     /**
  98.      * Undocumented function
  99.      *
  100.      * @param MailerInterface $mailer
  101.      * @param [type] $from
  102.      * @param array $to
  103.      * @param [type] $produit
  104.      * @param [type] $subject
  105.      * @param [type] $template
  106.      * @return void
  107.      */
  108.     public function sendEmailInvitation(MailerInterface $mailer$from$to = [], $produit$subject$template)
  109.     {
  110.         $email = (new TemplatedEmail())
  111.             ->from($from)
  112.             ->to($to)
  113.             ->subject($subject)
  114.             ->htmlTemplate($template)
  115.             ->context([
  116.                 'produit' => $produit,
  117.             ]);
  118.         $mailer->send($email);
  119.     }
  120.     public function resetPasswordMail(MailerInterface $mailer$from$to$name_to$subject$template$token)
  121.     {
  122.         $email = (new TemplatedEmail())
  123.             ->from('pharmadexi@gmail.com')
  124.             ->to($to)
  125.             ->subject($subject)
  126.             ->htmlTemplate($template)
  127.             ->context([
  128.                 'name' => $name_to,
  129.                 'token'  => $token
  130.             ]);
  131.         $mailer->send($email);
  132.     }
  133.     public function sendPropositionConfirmationPcie(MailerInterface $mailer$from$to$name_from$subject$template$proposition)
  134.     {
  135.         $email = (new TemplatedEmail())
  136.             ->from('pharmadexi@gmail.com')
  137.             ->to(...$to)
  138.             ->subject($subject)
  139.             ->htmlTemplate($template)
  140.             ->context([
  141.                 'name_from'   => $name_from,
  142.                 'propositions' => $proposition
  143.             ]);
  144.         $mailer->send($email);
  145.     }
  146.     public function sendEmailValidPaiementGrossiste(MailerInterface $mailer$from$to$subject$template$params = [])
  147.     {
  148.         $email = (new TemplatedEmail())
  149.             ->from($from)
  150.             ->to($to)
  151.             ->subject($subject)
  152.             ->htmlTemplate($template)
  153.             ->context($params);
  154.         $mailer->send($email);
  155.     }
  156.     //confirmation creation compte Pcie
  157.     public function sendConfirmCreationCompteUserFromAdmin(MailerInterface $mailer$from$to$subject$template$params = [])
  158.     {
  159.         $email = (new TemplatedEmail())
  160.             ->from($from)
  161.             ->to($to)
  162.             ->subject($subject)
  163.             ->htmlTemplate($template)
  164.             ->context($params);
  165.         $mailer->send($email);
  166.     }
  167.     public function sendFAQEmail(MailerInterface $mailer$subject$template$params)
  168.     {
  169.         $email = (new TemplatedEmail())
  170.             ->from($_ENV['MAIL_FROM'])
  171.             ->to($_ENV['MAIL_ADMIN'])
  172.             ->subject($subject)
  173.             ->htmlTemplate($template)
  174.             ->context($params);
  175.         $mailer->send($email);
  176.     }
  177.     //POUR L'API ICTUSPHARMA
  178.     public function sendMailResetPassword(MailerInterface $mailer$to$from$subject$template$params)
  179.     {
  180.         try {
  181.             $email = (new TemplatedEmail())
  182.                 ->from($from)
  183.                 ->to($to)
  184.                 ->subject($subject)
  185.                 ->htmlTemplate($template)
  186.                 ->context($params);
  187.             $mailer->send($email);
  188.         } catch (TransportException $e) {
  189.             return $e->getMessage();
  190.         }
  191.     }
  192.     public function sendMailResetPassword2(MailerInterface $mailer)
  193.     {
  194.         $email = (new Email())
  195.             ->from('hello@example.com')
  196.             ->to('erudit.andrianomentsoa@sopharmad.com')
  197.             ->subject('tetssts')
  198.             ->text('Sending emails is fun again!')
  199.             ->html('<p>See Twig integration for better HTML integration!</p>');
  200.         $mailer->send($email);
  201.     }
  202. }