<?php
namespace App\Services;
use Mailjet\Client;
use Mailjet\Resources;
use Symfony\Component\Mime\Email;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mailer\Exception\TransportException;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
class MailerServices
{
public function sendEmail(MailerInterface $mailer, $from, $to, $name_to, $subject, $template)
{
try {
$email = (new TemplatedEmail())
->from($from)
->to($to)
->subject($subject)
->htmlTemplate($template)
->context([
'name' => $name_to
]);
$mailer->send($email);
} catch (\Exception $e) {
return false;
}
}
public function sendMail(MailerInterface $mailer, $to, $from, $subject, $template, $params)
{
try {
/*Test*/
/* $from = "commande@ictuspharma.com";
$to = "zoanja@yahoo.fr"; */
/*Test*/
$email = (new TemplatedEmail())
->from($from)
->to($to)
->subject($subject)
->htmlTemplate($template)
->context($params);
$mailer->send($email);
} catch (TransportException $e) {
return null;
}
}
public function send(MailerInterface $mailer, $to, $from, $subject, $template, $params)
{
try {
/*Test*/
/* $from = "commande@ictuspharma.com";
$to = "zoanja@yahoo.fr"; */
/*Test*/
$email = (new TemplatedEmail())
->from($from)
->to($to)
->subject($subject)
->htmlTemplate($template)
->context($params);
$mailer->send($email);
} catch (TransportException $e) {
return null;
}
}
public function sendWithCc(MailerInterface $mailer, $to, $cc, $from, $subject, $template, $params)
{
try {
/*Test*/
/* $from = "commande@ictuspharma.com";
$to = "zoanja@yahoo.fr"; */
/*Test*/
$email = (new TemplatedEmail())
->from($from)
->to($to)
->cc($cc)
->subject($subject)
->htmlTemplate($template)
->context($params);
$mailer->send($email);
} catch (TransportException $e) {
return null;
}
}
public function sendEmailAdmin(MailerInterface $mailer, $from, $to, $name_client, $id_client, $subject, $template)
{
$email = (new TemplatedEmail())
->from($from)
->to($to)
->subject($subject)
->htmlTemplate($template)
->context([
'name' => $name_client,
'id_client' => $id_client
]);
$mailer->send($email);
}
/**
* Undocumented function
*
* @param MailerInterface $mailer
* @param [type] $from
* @param array $to
* @param [type] $produit
* @param [type] $subject
* @param [type] $template
* @return void
*/
public function sendEmailInvitation(MailerInterface $mailer, $from, $to = [], $produit, $subject, $template)
{
$email = (new TemplatedEmail())
->from($from)
->to($to)
->subject($subject)
->htmlTemplate($template)
->context([
'produit' => $produit,
]);
$mailer->send($email);
}
public function resetPasswordMail(MailerInterface $mailer, $from, $to, $name_to, $subject, $template, $token)
{
$email = (new TemplatedEmail())
->from('pharmadexi@gmail.com')
->to($to)
->subject($subject)
->htmlTemplate($template)
->context([
'name' => $name_to,
'token' => $token
]);
$mailer->send($email);
}
public function sendPropositionConfirmationPcie(MailerInterface $mailer, $from, $to, $name_from, $subject, $template, $proposition)
{
$email = (new TemplatedEmail())
->from('pharmadexi@gmail.com')
->to(...$to)
->subject($subject)
->htmlTemplate($template)
->context([
'name_from' => $name_from,
'propositions' => $proposition
]);
$mailer->send($email);
}
public function sendEmailValidPaiementGrossiste(MailerInterface $mailer, $from, $to, $subject, $template, $params = [])
{
$email = (new TemplatedEmail())
->from($from)
->to($to)
->subject($subject)
->htmlTemplate($template)
->context($params);
$mailer->send($email);
}
//confirmation creation compte Pcie
public function sendConfirmCreationCompteUserFromAdmin(MailerInterface $mailer, $from, $to, $subject, $template, $params = [])
{
$email = (new TemplatedEmail())
->from($from)
->to($to)
->subject($subject)
->htmlTemplate($template)
->context($params);
$mailer->send($email);
}
public function sendFAQEmail(MailerInterface $mailer, $subject, $template, $params)
{
$email = (new TemplatedEmail())
->from($_ENV['MAIL_FROM'])
->to($_ENV['MAIL_ADMIN'])
->subject($subject)
->htmlTemplate($template)
->context($params);
$mailer->send($email);
}
//POUR L'API ICTUSPHARMA
public function sendMailResetPassword(MailerInterface $mailer, $to, $from, $subject, $template, $params)
{
try {
$email = (new TemplatedEmail())
->from($from)
->to($to)
->subject($subject)
->htmlTemplate($template)
->context($params);
$mailer->send($email);
} catch (TransportException $e) {
return $e->getMessage();
}
}
public function sendMailResetPassword2(MailerInterface $mailer)
{
$email = (new Email())
->from('hello@example.com')
->to('erudit.andrianomentsoa@sopharmad.com')
->subject('tetssts')
->text('Sending emails is fun again!')
->html('<p>See Twig integration for better HTML integration!</p>');
$mailer->send($email);
}
}