/** * @inheritdoc */ public function send(string $to, string $from, string $template, array $tags = []) : bool { try { $apiKey = $this->config['api_key']; $mail = new Mail($from, ' ', $to, ' ', $tags); $mail->setTemplateId($template); $sender = new Sender($apiKey); $sender->client->mail()->send($mail); return true; } catch (Exception $ex) { return false; } }
/** * {@inheritdoc} */ public function send(Swift_Mime_Message $message, &$failedRecipients = null) { $this->beforeSendPerformed($message); $mail = new Mail(); $from = $message->getFrom(); $subject = $message->getSubject(); $content = new Content("text/html", $message->getBody()); foreach ($from as $fromAddress => $name) { $mail->setFrom(["name" => $name, "email" => $fromAddress]); } $mail->setSubject($subject); $mail->addContent($content); $to = $message->getTo(); $person = new Personalization(); foreach ($to as $toAddress => $name) { $person->addTo(["name" => $name, "email" => $toAddress]); } $mail->addPersonalization($person); /** @var Response $result */ $result = $this->sendgrid->client->mail()->send()->post($mail); if ($result instanceof Response && $result->statusCode() >= 200 && $result->statusCode() < 300) { return $result; } else { throw new SendGridTransportException($result); } }