You are here

public function ClientService::sendMessage in Sparkpost email 8.2

Same name and namespace in other branches
  1. 8 src/ClientService.php \Drupal\sparkpost\ClientService::sendMessage()

Sends the message.

Parameters

array $message: The sparkpost message.

Return value

array The body of the response.

Overrides ClientServiceInterface::sendMessage

File

src/ClientService.php, line 62

Class

ClientService
Client service that sends the mails.

Namespace

Drupal\sparkpost

Code

public function sendMessage(array $message) {
  $client = $this
    ->getClient();
  try {
    $promise = $client->transmissions
      ->post($message);
    $response = $promise
      ->wait();
    return $response
      ->getBody();
  } catch (\Exception $e) {
    \Drupal::logger('sparkpost')
      ->error($e
      ->getMessage());
    throw $e;
  }
}