function sparkpost_test_form_submit in Sparkpost email 7.2
Same name and namespace in other branches
- 7 sparkpost.admin.inc \sparkpost_test_form_submit()
Submit handler for sparkpost_test_form(), sends the test email.
File
- ./
sparkpost.admin.inc, line 197 - Admin callbacks.
Code
function sparkpost_test_form_submit($form, &$form_state) {
// If an address was given, send a test email message.
$test_address = $form_state['values']['sparkpost_test_address'];
global $language;
$params['subject'] = t('Drupal Sparkpost test email');
$params['body'] = array(
$form_state['values']['sparkpost_test_body'],
);
$params['include_attachment'] = $form_state['values']['include_attachment'];
$mailsystem = mailsystem_get();
// Check for empty mailsystem config for Sparkpost:
$primary_config = empty($mailsystem['sparkpost_test']) ? 'sparkpost' : 'sparkpost_test';
if (empty($mailsystem[$primary_config])) {
drupal_set_message(t('Automatically setting Sparkpost tests to go through Sparkpost API: SparkpostMailSystem was not previously configured in Mail System.'));
mailsystem_set(array(
'sparkpost_test' => 'SparkpostMailSystem',
));
}
elseif ($mailsystem[$primary_config] != 'SparkpostMailSystem') {
drupal_set_message(t('Mail System is configured to send Sparkpost Test messages through %system, not SparkpostMailSystem. To send tests through SparkpostMailSystem, go to !link and change the setting.', array(
'%system' => $mailsystem['sparkpost_test'],
'!link' => l(t('Mail System settings form'), 'admin/config/system/mailsystem'),
)), 'warning');
}
$result = drupal_mail('sparkpost', 'test', $test_address, $language, $params);
if (isset($result['result']) && $result['result'] == 'true') {
drupal_set_message(t('Sparkpost test email sent from %from to %to.', array(
'%from' => $result['from'],
'%to' => $result['to'],
)), 'status');
}
else {
$form_state['rebuild'] = TRUE;
}
}