src/Service/SendgridMailService.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Service;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Exception;
  5. class SendgridMailService
  6. {
  7.     protected $em;
  8.     protected $apiInstance;
  9.     public $typemail;
  10.     protected $destinataires = array();
  11.     protected $destinataires_copy = array();
  12.     private $API_KEY "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";
  13.     public function __construct(EntityManagerInterface $em)
  14.     {
  15.         $this->em $em;
  16.     }
  17.     
  18.     public function send($destinataires = array(), $content$subject$cc null){
  19.         $email = new \SendGrid\Mail\Mail();
  20.         $email->setFrom("support@spontaneit.fr""support@spontaneit.fr");
  21.         $email->setSubject($subject);
  22.         foreach($destinataires as $d){
  23.             $email->addTo($d$d);
  24.         }
  25.         $email->addContent("text/plain"$content);
  26.         $email->addContent("text/html"$content);
  27.         $sendgrid = new \SendGrid($this->API_KEY);
  28.         try {
  29.             $response $sendgrid->send($email);
  30.             return $response;
  31.         } catch (Exception $e) {
  32.             echo 'Caught exception: '$e->getMessage() ."\n";
  33.         }
  34.     }
  35. }