function sparkpost_mailsend in Sparkpost email 7.2
Same name and namespace in other branches
- 7 sparkpost.module \sparkpost_mailsend()
Sand mail using Guzzle and Sparkpost.
Parameters
SparkpostMessageWrapperInterface $message_wrapper: Message array.
Return value
bool
1 call to sparkpost_mailsend()
- SparkpostMailSystem::mail in includes/
sparkpost.mail.inc - Send the email message.
1 string reference to 'sparkpost_mailsend'
- sparkpost_cron_queue_info in ./
sparkpost.module - Implements hook_cron_queue_info().
File
- ./
sparkpost.module, line 174 - Sparkpost integration.
Code
function sparkpost_mailsend(SparkpostMessageWrapperInterface $message_wrapper) {
try {
if (!class_exists('\\Ivory\\HttpAdapter\\Guzzle6HttpAdapter') || !class_exists('\\GuzzleHttp\\Client') || !class_exists('\\SparkPost\\SparkPost')) {
throw new Exception('Missing Composer dependencies, check admin/config/system/composer-manager/packages');
}
$httpAdapter = new \Ivory\HttpAdapter\Guzzle6HttpAdapter(new \GuzzleHttp\Client());
$sparky = new \SparkPost\SparkPost($httpAdapter, [
'key' => variable_get('sparkpost_api_key'),
]);
// Set custom timeout value.
$config = $sparky->httpAdapter
->getConfiguration();
$config
->setTimeout(variable_get('sparkpost_timeout', 10));
$sparky->httpAdapter
->setConfiguration($config);
// Build your email and send it!
$results = $sparky->transmission
->send($message_wrapper
->getSparkpostMessage());
// Add results array to message wrapper.
$message_wrapper
->setResult($results);
// Let other modules do something on success.
module_invoke_all('sparkpost_mailsend_success', $message_wrapper);
return TRUE;
} catch (\SparkPost\APIResponseException $e) {
$message_wrapper
->setApiResponseException($e);
} catch (Exception $e) {
// Undefined exception.
watchdog_exception('sparkpost', $e);
}
// Let other modules do something on error.
module_invoke_all('sparkpost_mailsend_error', $message_wrapper);
return FALSE;
}