Exemplo n.º 1
0
 /**
  * mandril://APIKEY
  *
  * @param Envelope $envelope
  * @return bool
  * @throws MailApiException
  */
 public function send(Envelope $envelope)
 {
     $from = Util::decomposeEmail($envelope->getFrom());
     $fromName = $from['name'];
     $fromEmail = $from['email'];
     $bodyHtml = $envelope->getBody();
     $params = array();
     $params["key"] = $this->connection->getServer();
     $params["message"] = ['html' => $bodyHtml, 'subject' => $envelope->getSubject(), 'from_name' => $fromName, 'from_email' => $fromEmail, 'to' => [], 'headers' => ['Reply-To' => $envelope->getReplyTo()], "important" => false, "track_opens" => true, "track_clicks" => true, "auto_text" => true, "auto_html" => true];
     $params["async"] = true;
     $params["ip_pool"] = "Main Pool";
     $sendTo = array_unique(array_merge((array) $envelope->getTo(), (array) $envelope->getCC()));
     foreach ($sendTo as $email) {
         $params['message']['to'][] = ['email' => $email, 'type' => 'to'];
     }
     foreach ((array) $envelope->getBCC() as $email) {
         $params['message']['bcc_address'] = $email;
     }
     $json = json_encode($params);
     $request = new WebRequest('https://mandrillapp.com/api/1.0/messages/send.json');
     $result = $request->postPayload($json, 'application/json');
     if (!$result) {
         throw new MailApiException('Cannot connect to Mandrill Api');
     } else {
         $resultJson = json_decode($result, true);
         if ($resultJson[0]['status'] == 'error') {
             throw new MailApiException('Mandrill: ' . $resultJson[0]['message']);
         }
     }
     return true;
 }
Exemplo n.º 2
0
 /**
  * mandril://APIKEY
  *
  * @param Envelope $envelope
  * @throws Exception
  */
 public function send(Envelope $envelope)
 {
     $from = \ByJG\Mail\Util::decomposeEmail($envelope->getFrom());
     $fromName = $from['name'];
     $fromEmail = $from['email'];
     $bodyHtml = $envelope->getBody();
     $params["key"] = $this->connection->getServer();
     $params["message"] = ['html' => $bodyHtml, 'subject' => $envelope->getSubject(), 'from_name' => $fromName, 'from_email' => $fromEmail, 'to' => [], 'headers' => ['Reply-To' => $envelope->getReplyTo()], "important" => false, "track_opens" => true, "track_clicks" => true, "auto_text" => true, "auto_html" => true];
     $params["async"] = true;
     $params["ip_pool"] = "Main Pool";
     foreach ((array) $envelope->getTo() as $email) {
         $params['message']['to'][] = ['email' => $email, 'type' => 'to'];
     }
     foreach ((array) $envelope->getCC() as $email) {
         $params['message']['to'][] = ['email' => $email, 'type' => 'to'];
     }
     foreach ((array) $envelope->getBCC() as $email) {
         $params['message']['bcc_address'] = $email;
     }
     $json = json_encode($params);
     $ch = curl_init('https://mandrillapp.com/api/1.0/messages/send.json');
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Length: ' . strlen($json)));
     $result = curl_exec($ch);
     if (!$result) {
         throw new Exception('Cannot connect to Mandrill Api');
     } else {
         $resultJson = json_decode($result, true);
         if ($resultJson[0]['status'] == 'error') {
             throw new Exception('Mandrill: ' . $resultJson[0]['message']);
         }
     }
 }
Exemplo n.º 3
0
 /**
  *
  * @param Envelope $envelope
  * @return PHPMailerOverride
  */
 protected function prepareMailer(Envelope $envelope)
 {
     $mail = new PHPMailerOverride(true);
     // the true param means it will throw exceptions on errors, which we need to catch
     $mail->Subject = FromUTF8::toIso88591Email($envelope->getSubject());
     $mail->CharSet = "utf-8";
     if ($envelope->isHtml()) {
         $mail->msgHTML($envelope->getBody());
     } else {
         $mail->Body = $envelope->getBodyText();
     }
     $mail->isSMTP();
     // telling the class to use SMTP
     if ($this->connection->getProtocol() != "smtp") {
         $mail->SMTPSecure = $this->connection->getProtocol();
         // ssl ou tls!
     }
     $replyTo = Util::decomposeEmail($envelope->getReplyTo());
     $mail->addReplyTo($replyTo["email"], $replyTo["name"]);
     // Define From email
     $from = Util::decomposeEmail($envelope->getFrom());
     $mail->setFrom($from["email"], $from["name"]);
     // Add Recipients
     foreach ((array) $envelope->getTo() as $toItem) {
         $to = Util::decomposeEmail($toItem);
         $mail->addAddress($to["email"], $to["name"]);
     }
     // Add Carbon Copy
     foreach ((array) $envelope->getCC() as $ccItem) {
         $cc = Util::decomposeEmail($ccItem);
         $mail->addCC($cc["email"], $cc["name"]);
     }
     // Add Blind Carbon Copy
     foreach ((array) $envelope->getBCC() as $bccItem) {
         $bcc = Util::decomposeEmail($bccItem);
         $mail->addBCC($bcc["email"], $bcc["name"]);
     }
     // Attachments
     foreach ((array) $envelope->getAttachments() as $name => $value) {
         $mail->addAttachment($value['content'], $name, 'base64', $value['content-type']);
     }
     return $mail;
 }