annotate sites/all/modules/smtp/smtp.admin.inc @ 9:830c812b520f

added smtp module
author root <root@paio.local>
date Mon, 28 Oct 2013 15:34:27 +0000
parents
children
rev   line source
root@9 1 <?php
root@9 2
root@9 3 /**
root@9 4 * @file
root@9 5 * Administrative page code for the smtp module.
root@9 6 *
root@9 7 */
root@9 8
root@9 9
root@9 10 /**
root@9 11 * Administrative settings.
root@9 12 *
root@9 13 * @return
root@9 14 * An array containing form items to place on the module settings page.
root@9 15 */
root@9 16 function smtp_admin_settings() {
root@9 17 // Override the smtp_library variable.
root@9 18 if (module_exists('mimemail') &&
root@9 19 strpos(variable_get('smtp_library', ''), 'mimemail')) {
root@9 20 // don't touch smtp_library
root@9 21 }
root@9 22 else {
root@9 23 if (variable_get('smtp_on', 0)) {
root@9 24 $smtp_path = drupal_get_filename('module', 'smtp');
root@9 25 if ($smtp_path) {
root@9 26 variable_set('smtp_library', $smtp_path);
root@9 27 drupal_set_message(t('SMTP.module is active.'));
root@9 28 }
root@9 29 // If drupal can't find the path to the module, display an error.
root@9 30 else {
root@9 31 drupal_set_message(t("SMTP.module error: Can't find file."), 'error');
root@9 32 }
root@9 33 }
root@9 34 // If this module is turned off, delete the variable.
root@9 35 else {
root@9 36 variable_del('smtp_library');
root@9 37 drupal_set_message(t('SMTP.module is INACTIVE.'));
root@9 38 }
root@9 39 }
root@9 40
root@9 41 $form['onoff'] = array(
root@9 42 '#type' => 'fieldset',
root@9 43 '#title' => t('Install options'),
root@9 44 );
root@9 45 $form['onoff']['smtp_on'] = array(
root@9 46 '#type' => 'radios',
root@9 47 '#title' => t('Turn this module on or off'),
root@9 48 '#default_value' => variable_get('smtp_on', 0),
root@9 49 '#options' => array(1 => t('On'), 0 => t('Off')),
root@9 50 '#description' => t('To uninstall this module you must turn it off here first.'),
root@9 51 );
root@9 52
root@9 53 $form['server'] = array(
root@9 54 '#type' => 'fieldset',
root@9 55 '#title' => t('SMTP server settings'),
root@9 56 );
root@9 57 $form['server']['smtp_host'] = array(
root@9 58 '#type' => 'textfield',
root@9 59 '#title' => t('SMTP server'),
root@9 60 '#default_value' => variable_get('smtp_host', ''),
root@9 61 '#description' => t('The address of your outgoing SMTP server.'),
root@9 62 );
root@9 63 $form['server']['smtp_hostbackup'] = array(
root@9 64 '#type' => 'textfield',
root@9 65 '#title' => t('SMTP backup server'),
root@9 66 '#default_value' => variable_get('smtp_hostbackup', ''),
root@9 67 '#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.'),
root@9 68 );
root@9 69 $form['server']['smtp_port'] = array(
root@9 70 '#type' => 'textfield',
root@9 71 '#title' => t('SMTP port'),
root@9 72 '#size' => 6,
root@9 73 '#maxlength' => 6,
root@9 74 '#default_value' => variable_get('smtp_port', '25'),
root@9 75 '#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'))),
root@9 76 );
root@9 77 // Only display the option if openssl is installed.
root@9 78 if (function_exists('openssl_open')) {
root@9 79 $encryption_options = array(
root@9 80 'standard' => t('No'),
root@9 81 'ssl' => t('Use SSL'),
root@9 82 'tls' => t('Use TLS'),
root@9 83 );
root@9 84 $encryption_description = t('This allows connection to an SMTP server that requires SSL encryption such as Gmail.');
root@9 85 }
root@9 86 // If openssl is not installed, use normal protocol.
root@9 87 else {
root@9 88 variable_set('smtp_protocol', 'standard');
root@9 89 $encryption_options = array('standard' => t('No'));
root@9 90 $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')));
root@9 91 }
root@9 92 $form['server']['smtp_protocol'] = array(
root@9 93 '#type' => 'select',
root@9 94 '#title' => t('Use encrypted protocol'),
root@9 95 '#default_value' => variable_get('smtp_protocol', 'standard'),
root@9 96 '#options' => $encryption_options,
root@9 97 '#description' => $encryption_description,
root@9 98 );
root@9 99
root@9 100 $form['auth'] = array(
root@9 101 '#type' => 'fieldset',
root@9 102 '#title' => t('SMTP Authentication'),
root@9 103 '#description' => t('Leave blank if your SMTP server does not require authentication.'),
root@9 104 );
root@9 105 $form['auth']['smtp_username'] = array(
root@9 106 '#type' => 'textfield',
root@9 107 '#title' => t('Username'),
root@9 108 '#default_value' => variable_get('smtp_username', ''),
root@9 109 '#description' => t('SMTP Username.'),
root@9 110 );
root@9 111 $form['auth']['smtp_password'] = array(
root@9 112 '#type' => 'password',
root@9 113 '#title' => t('Password'),
root@9 114 '#default_value' => variable_get('smtp_password', ''),
root@9 115 '#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.'),
root@9 116 );
root@9 117
root@9 118 $form['email_options'] = array(
root@9 119 '#type' => 'fieldset',
root@9 120 '#title' => t('E-mail options'),
root@9 121 );
root@9 122 $form['email_options']['smtp_from'] = array(
root@9 123 '#type' => 'textfield',
root@9 124 '#title' => t('E-mail from address'),
root@9 125 '#default_value' => variable_get('smtp_from', ''),
root@9 126 '#description' => t('The e-mail address that all e-mails will be from.'),
root@9 127 );
root@9 128 $form['email_options']['smtp_fromname'] = array(
root@9 129 '#type' => 'textfield',
root@9 130 '#title' => t('E-mail from name'),
root@9 131 '#default_value' => variable_get('smtp_fromname', ''),
root@9 132 '#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'),
root@9 133 );
root@9 134 $form['email_options']['smtp_allowhtml'] = array(
root@9 135 '#type' => 'checkbox',
root@9 136 '#title' => t('Allow to send e-mails formated as Html'),
root@9 137 '#default_value' => variable_get('smtp_allowhtml', 0),
root@9 138 '#description' => t('Checking this box will allow Html formated e-mails to be sent with the SMTP protocol.'),
root@9 139 );
root@9 140
root@9 141 // If an address was given, send a test e-mail message.
root@9 142 $test_address = variable_get('smtp_test_address', '');
root@9 143 if ($test_address != '') {
root@9 144 // Clear the variable so only one message is sent.
root@9 145 variable_del('smtp_test_address');
root@9 146 global $language;
root@9 147 $params['subject'] = t('Drupal SMTP test e-mail');
root@9 148 $params['body'] = array(t('If you receive this message it means your site is capable of using SMTP to send e-mail.'));
root@9 149 drupal_mail('smtp', 'smtp-test', $test_address, $language, $params);
root@9 150 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/reports/dblog'))));
root@9 151 }
root@9 152 $form['email_test'] = array(
root@9 153 '#type' => 'fieldset',
root@9 154 '#title' => t('Send test e-mail'),
root@9 155 );
root@9 156 $form['email_test']['smtp_test_address'] = array(
root@9 157 '#type' => 'textfield',
root@9 158 '#title' => t('E-mail address to send a test e-mail to'),
root@9 159 '#default_value' => '',
root@9 160 '#description' => t('Type in an address to have a test e-mail sent there.'),
root@9 161 );
root@9 162
root@9 163 $form['smtp_debugging'] = array(
root@9 164 '#type' => 'checkbox',
root@9 165 '#title' => t('Enable debugging'),
root@9 166 '#default_value' => variable_get('smtp_debugging', 0),
root@9 167 '#description' => t('Checking this box will print SMTP messages from the server for every e-mail that is sent.'),
root@9 168 );
root@9 169
root@9 170 return system_settings_form($form);
root@9 171 } // End of smtp_admin_settings().
root@9 172
root@9 173
root@9 174
root@9 175 /**
root@9 176 * Validation for the administrative settings form.
root@9 177 *
root@9 178 * @param form
root@9 179 * An associative array containing the structure of the form.
root@9 180 * @param form_state
root@9 181 * A keyed array containing the current state of the form.
root@9 182 */
root@9 183 function smtp_admin_settings_validate($form, &$form_state) {
root@9 184 if ($form_state['values']['smtp_on'] == 1 && $form_state['values']['smtp_host'] == '') {
root@9 185 form_set_error('smtp_host', t('You must enter an SMTP server address.'));
root@9 186 }
root@9 187
root@9 188 if ($form_state['values']['smtp_on'] == 1 && $form_state['values']['smtp_port'] == '') {
root@9 189 form_set_error('smtp_port', t('You must enter an SMTP port number.'));
root@9 190 }
root@9 191
root@9 192 if ($form_state['values']['smtp_from'] && !valid_email_address($form_state['values']['smtp_from'])) {
root@9 193 form_set_error('smtp_from', t('The provided from e-mail address is not valid.'));
root@9 194 }
root@9 195
root@9 196 // If username is set empty, we must set both username/password empty as well.
root@9 197 if (empty($form_state['values']['smtp_username'])) {
root@9 198 $form_state['values']['smtp_password'] = '';
root@9 199 }
root@9 200
root@9 201 // A little hack. When form is presentend, the password is not shown (Drupal way of doing).
root@9 202 // So, if user submits the form without changing the password, we must prevent it from being reset.
root@9 203 elseif (empty($form_state['values']['smtp_password'])) {
root@9 204 unset($form_state['values']['smtp_password']);
root@9 205 }
root@9 206 } // End of smtp_admin_settings_validate().
root@9 207