You are here

function phpmailer_settings_form_submit in PHPMailer 7.4

Same name and namespace in other branches
  1. 5.2 phpmailer.admin.inc \phpmailer_settings_form_submit()
  2. 6.3 phpmailer.admin.inc \phpmailer_settings_form_submit()
  3. 6.2 phpmailer.admin.inc \phpmailer_settings_form_submit()
  4. 7.3 phpmailer.admin.inc \phpmailer_settings_form_submit()

Form submit function.

See also

phpmailer_settings_form()

1 string reference to 'phpmailer_settings_form_submit'
phpmailer_settings_form in ./phpmailer.admin.inc
Form builder for both the Mime Mail settings and our own settings page.

File

./phpmailer.admin.inc, line 294
Administrative functions for PHPMailer integration module.

Code

function phpmailer_settings_form_submit($form, &$form_state) {

  // Enable/disable mail sending subsystem.
  if ($form_state['values']['smtp_on']) {
    if (!phpmailer_enabled()) {
      $mail_system = variable_get('mail_system', array(
        'default-system' => 'DefaultMailSystem',
      ));
      $mail_system['default-system'] = 'DrupalPHPMailer';
      variable_set('mail_system', $mail_system);
      drupal_set_message(t('PHPMailer will be used to deliver all site e-mails.'));
      watchdog('phpmailer', 'PHPMailer has been enabled.');
    }
  }
  elseif (phpmailer_enabled()) {

    // Remove PHPMailer from all mail keys it is configured for.
    $mail_system = variable_get('mail_system', array(
      'default-system' => 'DefaultMailSystem',
    ));
    foreach ($mail_system as $key => $class) {
      if ($class == 'DrupalPHPMailer') {
        if ($key != 'default-system') {
          unset($mail_system[$key]);
        }
        else {
          $mail_system[$key] = 'DefaultMailSystem';
        }
      }
    }
    variable_set('mail_system', $mail_system);
    drupal_set_message(t('PHPMailer has been disabled.'));
    watchdog('phpmailer', 'PHPMailer has been disabled.');
  }

  // Log configuration changes.
  $settings = array(
    'host',
    'port',
    'protocol',
    'username',
  );

  // Ignore empty passwords if hide password is active.
  if (variable_get('smtp_hide_password', 0) && $form_state['values']['smtp_password'] == '') {
    unset($form_state['values']['smtp_password']);
  }
  else {
    $settings[] = 'password';
  }
  foreach ($settings as $setting) {
    if ($form_state['values']['smtp_' . $setting] != variable_get('smtp_' . $setting, '')) {
      watchdog('phpmailer', 'SMTP configuration changed.');
      break;
    }
  }
}