Esempio n. 1
0
 protected function _send($email, MessageInterface $message)
 {
     $slackApiKey = env("SLACK_APIKEY");
     //上で作成したAPIキー
     $channel = env("SLACK_CHANNEL");
     $time = date("Y-m-d H:i:s");
     $text = "\n\n\n        ";
     $data = ["token" => $slackApiKey, "text" => $text, "channel" => $channel];
     $data["icon_emoji"] = ":mailbox_with_mail:";
     $data["username"] = "******";
     $data["text"] = "SLACK DEBUG MAILER";
     $data["attachments"] = json_encode([["color" => "#36a64f", "pretext" => "MESSAGE DERIVERED AT {$time}", "title" => "[TO] {$email}      [FROM] {$message->getFrom()}", "title_link" => "", "text" => "\nSUBJECT: {$message->getSubject()}\nTEXT: {$message->getTextBody()}\n                "]]);
     $url = "https://slack.com/api/chat.postMessage?" . http_build_query($data);
     $res = file_get_contents($url);
 }
Esempio n. 2
0
 public function send(MessageInterface $message)
 {
     if (count($message->getToList()) === 0) {
         // TODO FIXED EXCEPTION
         throw new \Exception();
     }
     foreach ($message->getToList() as $email) {
         if (!$this->validateEmail($email)) {
             // TODO FIXED EXCEPTION
             throw new \Exception();
         }
     }
     $sendgrid = new \SendGrid(env("SENDGRID_USERNAME"), env("SENDGRID_PASSWORD"));
     $email = new \SendGrid\Email();
     $email->addTo($message->getToList())->setFrom($message->getFrom())->setSubject($message->getSubject())->setText($message->getTextBody())->setHtml($message->getHtmlBody());
     if (is_array($message->getBccList())) {
         $email->addBcc($message->getBccList());
     }
     $email->setAttachments($message->getAttachments());
     try {
         $sendgrid->send($email);
     } catch (\Exception $e) {
         throw $e;
     }
 }