$address, 'name' => $name]; }; $from = $message->message->getFrom(); $to = $message->message->getTo(); $data = [ 'sender' => ['email' => array_key_first($from), 'name' => array_first($from)], 'to' => array_map($format_callback, array_keys($to), array_values($to)), 'subject' => $message->message->getSubject(), 'htmlContent' => $message->message->getBody(), ]; if ($cc = $message->message->getCc()) { $data['cc'] = array_map($format_callback, array_keys($cc), array_values($cc)); } if ($bcc = $message->message->getBcc()) { $data['bcc'] = array_map($format_callback, array_keys($bcc), array_values($bcc)); } if ($reply_to = $message->message->getReplyTo()) { $data['replyTo'] = ['email' => array_key_first($reply_to)]; } foreach ($message->getAttachments() as $attachment) { $data['attachment'][] = [ 'content' => base64_encode(file_get_contents($attachment->local_filename)), 'name' => $attachment->display_filename ?: $attachment->cid, ]; } // Prepare headers and options for Requests. $headers = [ 'api-key' => $this->_config['api_key'], 'Content-Type' => 'application/json', 'User-Agent' => 'PHP', ]; $options = [ 'timeout' => 8, ]; // Send the API request. $request = \Rhymix\Framework\HTTP::post(self::$_url, $data, $headers, [], $options); $status_code = $request->getStatusCode(); $result = @json_decode($request->getBody()->getContents()); // Parse the result. if (!$result) { $message->errors[] = 'Brevo: Connection error: ' . $request->getBody()->getContents(); return false; } elseif ($status_code === 400) { $message->errors[] = 'Brevo: Bad request: ' . $result->message; return false; } else { return true; } } }