<?php
namespace App\Service;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
class SendgridMailService
{
protected $em;
protected $apiInstance;
public $typemail;
protected $destinataires = array();
protected $destinataires_copy = array();
private $API_KEY = "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";
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function send($destinataires = array(), $content, $subject, $cc = null){
$email = new \SendGrid\Mail\Mail();
$email->setFrom("support@spontaneit.fr", "support@spontaneit.fr");
$email->setSubject($subject);
foreach($destinataires as $d){
$email->addTo($d, $d);
}
$email->addContent("text/plain", $content);
$email->addContent("text/html", $content);
$sendgrid = new \SendGrid($this->API_KEY);
try {
$response = $sendgrid->send($email);
return $response;
} catch (Exception $e) {
echo 'Caught exception: '. $e->getMessage() ."\n";
}
}
}