You are here

function mandrill_test_form_submit in Mandrill 7

Same name and namespace in other branches
  1. 6 mandrill.admin.inc \mandrill_test_form_submit()
  2. 7.2 mandrill.admin.inc \mandrill_test_form_submit()

Submit handler for mandrill_test_form(), sends the test email.

File

./mandrill.admin.inc, line 270
Administrative forms for Mandrill module.

Code

function mandrill_test_form_submit($form, &$form_state) {

  // If an address was given, send a test email message.
  $test_address = $form_state['values']['mandrill_test_address'];
  global $language;
  $params['subject'] = t('Drupal Mandrill test email');
  $params['body'] = $form_state['values']['mandrill_test_body'];
  $params['include_attachment'] = $form_state['values']['include_attachment'];
  $mailsystem = mailsystem_get();

  // Check for empty mailsystem config for Mandrill:
  if (empty($mailsystem['mandrill_test'])) {
    drupal_set_message(t('Automatically setting Mandrill tests to go through Mandrill API: MandrillMailSystem was not previously configured in Mail System.'));
    mailsystem_set(array(
      'mandrill_test' => 'MandrillMailSystem',
    ));
  }
  elseif ($mailsystem['mandrill_test'] != 'MandrillMailSystem') {
    drupal_set_message(t('Mail System is configured to send Mandrill Test messages through %system, not Mandrill. To send tests through Mandrill, go to !link and change the setting.', array(
      '%system' => $mailsystem['mandrill_test'],
      '!link' => l(t('Mandrill'), 'https://mandrillapp.com/templates'),
    )), 'warning');

    // Hack because we are apparently formatting the body differently than
    // default drupal messages.
    $params['body'] = array(
      '0' => $params['body'],
    );
  }
  $result = drupal_mail('mandrill', 'test', $test_address, $language, $params);
  if (isset($result['result']) && $result['result'] == 'true') {
    drupal_set_message(t('Mandrill test email sent from %from to %to.', array(
      '%from' => $result['from'],
      '%to' => $result['to'],
    )), 'status');
  }
}