コード例 #1
0
 public function sendContent($from, $to, $subject, $type, $content)
 {
     if (is_string($to)) {
         $to = [$to];
     }
     $recipients = Mailjet::parse_recipient_type($to);
     // Build the HTTP POST body text
     if ($type == 'html') {
         $body = http_build_query(array('from' => $from, 'to' => implode(', ', $recipients['to']), 'cc' => implode(', ', $recipients['cc']), 'bcc' => implode(', ', $recipients['bcc']), 'subject' => $subject, 'html' => $content));
     } else {
         if ($type == 'text') {
             $body = http_build_query(array('from' => $from, 'to' => implode(', ', $recipients['to']), 'cc' => implode(', ', $recipients['cc']), 'bcc' => implode(', ', $recipients['bcc']), 'subject' => $subject, 'text' => $content));
         } else {
             throw new Exception('Wrong email type');
         }
     }
     utils::log($body);
     $options = array('scheme' => 'http', 'host' => 'api.mailjet.com', 'path' => '/v3/send/');
     $endpoint = Mailjet::unparse_url($options);
     $headers = array('Authorization' => 'Basic ' . $this->_authentificate, 'Content-Type' => 'application/x-www-form-urlencoded', 'Content-Length' => strlen($body));
     // API request
     Unirest\Request::verifyPeer(false);
     $response = Unirest\Request::post($endpoint, $headers, $body);
     utils::log('STATUS: ' . $response->code);
     utils::log('HEADERS: ' . json_encode($response->headers));
     utils::log('BODY: ' . $response->raw_body);
     return $response->code == 200;
 }