You are here

function mailgun_get_client in Mailgun 7

Get the Mailgun client to access Mailgun's endpoints.

Parameters

string $key: The Mailgun API key. Leave empty to use the API key saved in database.

Return value

\Mailgun\Mailgun|FALSE Mailgun object or FALSE if Mailgun settings are not correct.

3 calls to mailgun_get_client()
mailgun_admin_settings in ./mailgun.admin.inc
Menu callback: displays the Mailgun module settings page.
mailgun_admin_settings_validate in ./mailgun.admin.inc
Form validation handler for mailgun_admin_settings().
mailgun_send in ./mailgun.module
Send an e-mail using the Mailgun API.

File

./mailgun.module, line 186
Provides integration with Mailgun's email sending API.

Code

function mailgun_get_client($key = '', $endpoint = '') {

  // Check if the Mailgun PHP library is installed.
  if (!mailgun_check_library()) {
    watchdog('mailgun', 'Mailgun client initialization failed: Unable to load the Mailgun PHP library.', array(), WATCHDOG_ERROR);
    return FALSE;
  }
  $key = empty($key) ? variable_get('mailgun_api_key', '') : $key;
  if (empty($key)) {
    watchdog('mailgun', 'Mailgun client initialization failed: Missing API key.', array(), WATCHDOG_ERROR);
    return FALSE;
  }
  $endpoint = empty($endpoint) ? variable_get(MAILGUN_API_ENDPOINT, 'https://api.mailgun.net') : $endpoint;
  return Mailgun::create($key, $endpoint);
}