コード例 #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;
 }
コード例 #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']);
         }
     }
 }
コード例 #3
0
 /**
  *
  * @param Envelope $envelope
  * @throws Exception
  */
 public function send(Envelope $envelope)
 {
     $mail = $this->prepareMailer($envelope);
     $mail->Host = $this->connection->getServer();
     $mail->Port = $this->connection->getPort();
     if (!empty($this->connection->getUsername())) {
         $mail->SMTPAuth = true;
         $mail->Username = $this->connection->getUsername();
         // SMTP account username
         $mail->Password = $this->connection->getPassword();
         // SMTP account password
     }
     if (!$mail->Send()) {
         throw new Exception($mail->ErrorInfo);
     }
 }
コード例 #4
0
ファイル: Envelope.php プロジェクト: byjg/mailwrapper
 /**
  *
  * @param MailConnection $connection
  * @return MailWrapperInterface
  * @throws InvalidArgumentException
  */
 public static function mailerFactory(MailConnection $connection)
 {
     $protocol = $connection->getProtocol();
     if (in_array($protocol, ['smtp', 'ssl', 'tls'])) {
         $mail = new PHPMailerWrapper($connection);
     } elseif ($protocol === "ses") {
         $mail = new AmazonSesWrapper($connection);
     } elseif ($protocol === "mandrill") {
         $mail = new MandrillApiWrapper($connection);
     } elseif ($protocol === "sendmail") {
         $mail = new SendMailWrapper($connection);
     } elseif ($protocol === "mailgun") {
         $mail = new MailgunApiWrapper($connection);
     } else {
         throw new InvalidArgumentException("Connection '" . $connection->getProtocol() . "' is not valid");
     }
     return $mail;
 }