You are here

function smtp_admin_provider_settings in SMTP Authentication Support 7.2

Administrative settings.

Parameters

machine_name: The provider identifier inside the provider array

Return value

An array containing form items to place on the provider edit page.

1 string reference to 'smtp_admin_provider_settings'
smtp_menu in ./smtp.module
Implements hook_menu().

File

./smtp.admin.inc, line 363
Administrative page code for the smtp module.

Code

function smtp_admin_provider_settings($form, $form_state, $machine_name = NULL) {
  $form = array();
  $providers = variable_get('smtp_providers', array());
  if (!empty($machine_name) && empty($providers[$machine_name])) {
    drupal_set_message(t('Invalid provider id.'), 'error');
    return $form;
  }
  $form['server'] = array(
    '#type' => 'fieldset',
    '#title' => t('SMTP server settingssss'),
  );
  $form['server']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#default_value' => !empty($providers[$machine_name]['name']) ? $providers[$machine_name]['name'] : '',
    //If we are editing a profile, we shouldn't be able to change the machine name
    '#description' => t("The provider machine name. It should be composed only of alphanumeric characters and underscores and should not start with a underscore."),
  );
  $form['machine_name'] = array(
    '#type' => 'machine_name',
    '#title' => t('Machine Name'),
    '#default_value' => !empty($providers[$machine_name]['machine_name']) ? $providers[$machine_name]['machine_name'] : NULL,
    '#machine_name' => array(
      'exists' => 'smtp_provider_machine_name_exist',
      'source' => array(
        'server',
        'name',
      ),
    ),
  );
  $form['server']['smtp_host'] = array(
    '#type' => 'textfield',
    '#title' => t('SMTP server'),
    '#default_value' => !empty($providers[$machine_name]['smtp_host']) ? $providers[$machine_name]['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' => !empty($providers[$machine_name]['smtp_hostbackup']) ? $providers[$machine_name]['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' => !empty($providers[$machine_name]['smtp_port']) ? $providers[$machine_name]['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'),
    )),
  );

  // Only display the option if openssl is installed.
  if (function_exists('openssl_open')) {
    $encryption_options = array(
      'standard' => t('No'),
      'ssl' => t('Use SSL'),
      'tls' => t('Use TLS'),
    );
    $encryption_description = t('This allows connection to a SMTP server that requires SSL encryption such as Gmail.');
  }
  else {
    $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' => !empty($providers[$machine_name]['smtp_protocol']) ? $providers[$machine_name]['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' => !empty($providers[$machine_name]['smtp_username']) ? $providers[$machine_name]['smtp_username'] : '',
    '#description' => t('SMTP Username.'),
  );
  $form['auth']['smtp_password'] = array(
    '#type' => 'password',
    '#title' => t('Password'),
    '#default_value' => !empty($providers[$machine_name]['smtp_password']) ? $providers[$machine_name]['smtp_password'] : '',
    '#description' => t('SMTP password. If you have already entered your password before, you should leave this field blank, unless you want to change the stored 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 address'),
    '#default_value' => !empty($providers[$machine_name]['smtp_from']) ? $providers[$machine_name]['smtp_from'] : '',
    '#description' => t('The e-mail address that all e-mails will be from.'),
  );
  $form['email_options']['smtp_fromname'] = array(
    '#type' => 'textfield',
    '#title' => t('E-mail from name'),
    '#default_value' => !empty($providers[$machine_name]['smtp_fromname']) ? $providers[$machine_name]['smtp_fromname'] : '',
    '#description' => t('The name that all e-mails will be from. If left blank will use the site name of:') . ' ' . variable_get('site_name', 'Drupal powered site'),
  );
  $form['email_options']['smtp_allowhtml'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow to send e-mails formatted as Html'),
    '#default_value' => !empty($providers[$machine_name]['smtp_allowhtml']) ? $providers[$machine_name]['smtp_allowhtml'] : '',
    '#description' => t('Checking this box will allow Html formatted e-mails to be sent with the SMTP protocol.'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  return $form;
}