You are here

function smtp_admin_settings in SMTP Authentication Support 5

Same name and namespace in other branches
  1. 6 smtp.module \smtp_admin_settings()
  2. 7.2 smtp.admin.inc \smtp_admin_settings()
  3. 7 smtp.admin.inc \smtp_admin_settings()

Settings Hook

Return value

An array containing form items to place on the module settings page.

1 string reference to 'smtp_admin_settings'
smtp_menu in ./smtp.module
Implementation of hook_menu().

File

./smtp.module, line 41
Enables drupal to send email directly to an SMTP server using authentication. Uses the PHPMailer class by Brent R. Matzelle.

Code

function smtp_admin_settings() {

  // only administrators can access this module
  if (!user_access('administer site configuration')) {
    return message_access();
  }

  //Override the smtp_library variable.
  if (variable_get('smtp_on', 0)) {
    $smtp_path = drupal_get_filename('module', 'smtp');
    if ($smtp_path) {
      if (!module_exists('mimemail') || module_exists('mimemail') && variable_get('mimemail_alter', 0) == 0) {
        variable_set('smtp_library', $smtp_path);
      }
      drupal_set_message(t('SMTP.module is active.'));
    }
    else {

      //If drupal can't find the path to the module.
      drupal_set_message(t("SMTP.module error: Can't find file."), 'error');
    }
  }
  else {

    //If smtp is turned off delete the variable.
    variable_del('smtp_library');
    drupal_set_message(t('SMTP.module is INACTIVE.'));
  }
  $form['onoff'] = array(
    '#type' => 'fieldset',
    '#title' => t('Install options'),
  );
  $form['onoff']['smtp_on'] = array(
    '#type' => 'radios',
    '#title' => t('Turn this module On or Off'),
    '#default_value' => variable_get('smtp_on', 0),
    '#options' => array(
      1 => t('On'),
      0 => t('Off'),
    ),
    '#description' => t('To uninstall this module you must turn it off here first.'),
  );
  $form['server'] = array(
    '#type' => 'fieldset',
    '#title' => t('SMTP server settings'),
  );
  $form['server']['smtp_host'] = array(
    '#type' => 'textfield',
    '#title' => t('SMTP Server'),
    '#default_value' => variable_get('smtp_host', ''),
    '#description' => t('The address of your outgoing SMTP server.'),
  );
  $form['server']['smtp_hostbackup'] = array(
    '#type' => 'textfield',
    '#title' => t('SMTP Backup Server'),
    '#default_value' => variable_get('smtp_hostbackup', ''),
    '#description' => t('The address of your outgoing SMTP backup server. If the primary server can\'t be found this one will be tried. This is optional.'),
  );
  $form['server']['smtp_port'] = array(
    '#type' => 'textfield',
    '#title' => t('SMTP port'),
    '#size' => 6,
    '#maxlength' => 6,
    '#default_value' => variable_get('smtp_port', '25'),
    '#description' => t('The default SMTP port is 25, if that is being blocked try 80. Gmail uses 465. See !url for more information on configuring for use with Gmail.', array(
      '!url' => l(t('this page'), 'http://gmail.google.com/support/bin/answer.py?answer=13287'),
    )),
  );
  if (function_exists('openssl_open')) {

    //Only display the option if openssl is installed.
    $encryption_options = array(
      'standard' => t('No'),
      'ssl' => t('Use SSL'),
      'tls' => t('Use TLS'),
    );
    $encryption_description = t('This allows connection to an SMTP server that requires SSL encryption such as Gmail.');
  }
  else {

    //If openssl is not installed use normal protocol.
    variable_set('smtp_protocol', 'standard');
    $encryption_options = array(
      'standard' => t('No'),
    );
    $encryption_description = t('Your PHP installation does not have SSL enabled. See the !url page on php.net for more information. Gmail requires SSL.', array(
      '!url' => l(t('OpenSSL Functions'), 'http://php.net/openssl'),
    ));
  }
  $form['server']['smtp_protocol'] = array(
    '#type' => 'select',
    '#title' => t('Use encrypted protocol'),
    '#default_value' => variable_get('smtp_protocol', 'standard'),
    '#options' => $encryption_options,
    '#description' => $encryption_description,
  );
  $form['auth'] = array(
    '#type' => 'fieldset',
    '#title' => t('SMTP Authentication'),
    '#description' => t('Leave blank if your SMTP server does not require authentication.'),
  );
  $form['auth']['smtp_username'] = array(
    '#type' => 'textfield',
    '#title' => t('Username'),
    '#default_value' => variable_get('smtp_username', ''),
    '#description' => t('SMTP Username.'),
  );
  $form['auth']['smtp_password'] = array(
    '#type' => 'textfield',
    '#title' => t('Password'),
    '#default_value' => variable_get('smtp_password', ''),
    '#description' => t('SMTP password.'),
  );
  $form['email_options'] = array(
    '#type' => 'fieldset',
    '#title' => t('E-mail options'),
  );
  $form['email_options']['smtp_from'] = array(
    '#type' => 'textfield',
    '#title' => t('E-mail from'),
    '#default_value' => variable_get('smtp_from', ''),
    '#description' => t('The E-mail-address that all emails will be from.'),
  );
  $form['email_options']['smtp_fromname'] = array(
    '#type' => 'textfield',
    '#title' => t('E-mail from Name'),
    '#default_value' => variable_get('smtp_fromname', ''),
    '#description' => t('The name that all emails will be from. If left blank will use the site name of: ') . variable_get('site_name', 'Drupal powered site'),
  );

  //If an address was given, send a test email message.
  $test_address = variable_get('smtp_test_address', '');
  if ($test_address != '') {
    variable_del('smtp_test_address');

    //Clear the variable so only one message is sent.
    drupal_mail('smtp-test', $test_address, t('Drupal test email'), t('If you receive this message it means your site is capable of sending email.'));
    drupal_set_message(t('A test E-mail has been sent to @email. You may want to !check for any error messages.', array(
      '@email' => $test_address,
      '!check' => l(t('check the logs'), 'admin/logs/watchdog'),
    )));
  }
  $form['email_test'] = array(
    '#type' => 'fieldset',
    '#title' => t('Send test E-mail'),
  );
  $form['email_test']['smtp_test_address'] = array(
    '#type' => 'textfield',
    '#title' => t('E-mail address to send test email too'),
    '#default_value' => '',
    '#description' => t('Type in an address to have a test email sent there.'),
  );
  $form['smtp_debugging'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable debugging'),
    '#default_value' => variable_get('smtp_debugging', 0),
    '#description' => t('Checking this box will print SMTP messages from the server for every e-mail that is sent.'),
  );
  return system_settings_form($form);
}