root@9: 'fieldset', root@9: '#title' => t('Install options'), root@9: ); root@9: $form['onoff']['smtp_on'] = array( root@9: '#type' => 'radios', root@9: '#title' => t('Turn this module on or off'), root@9: '#default_value' => variable_get('smtp_on', 0), root@9: '#options' => array(1 => t('On'), 0 => t('Off')), root@9: '#description' => t('To uninstall this module you must turn it off here first.'), root@9: ); root@9: root@9: $form['server'] = array( root@9: '#type' => 'fieldset', root@9: '#title' => t('SMTP server settings'), root@9: ); root@9: $form['server']['smtp_host'] = array( root@9: '#type' => 'textfield', root@9: '#title' => t('SMTP server'), root@9: '#default_value' => variable_get('smtp_host', ''), root@9: '#description' => t('The address of your outgoing SMTP server.'), root@9: ); root@9: $form['server']['smtp_hostbackup'] = array( root@9: '#type' => 'textfield', root@9: '#title' => t('SMTP backup server'), root@9: '#default_value' => variable_get('smtp_hostbackup', ''), root@9: '#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: ); root@9: $form['server']['smtp_port'] = array( root@9: '#type' => 'textfield', root@9: '#title' => t('SMTP port'), root@9: '#size' => 6, root@9: '#maxlength' => 6, root@9: '#default_value' => variable_get('smtp_port', '25'), root@9: '#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: ); root@9: // Only display the option if openssl is installed. root@9: if (function_exists('openssl_open')) { root@9: $encryption_options = array( root@9: 'standard' => t('No'), root@9: 'ssl' => t('Use SSL'), root@9: 'tls' => t('Use TLS'), root@9: ); root@9: $encryption_description = t('This allows connection to an SMTP server that requires SSL encryption such as Gmail.'); root@9: } root@9: // If openssl is not installed, use normal protocol. root@9: else { root@9: variable_set('smtp_protocol', 'standard'); root@9: $encryption_options = array('standard' => t('No')); root@9: $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: } root@9: $form['server']['smtp_protocol'] = array( root@9: '#type' => 'select', root@9: '#title' => t('Use encrypted protocol'), root@9: '#default_value' => variable_get('smtp_protocol', 'standard'), root@9: '#options' => $encryption_options, root@9: '#description' => $encryption_description, root@9: ); root@9: root@9: $form['auth'] = array( root@9: '#type' => 'fieldset', root@9: '#title' => t('SMTP Authentication'), root@9: '#description' => t('Leave blank if your SMTP server does not require authentication.'), root@9: ); root@9: $form['auth']['smtp_username'] = array( root@9: '#type' => 'textfield', root@9: '#title' => t('Username'), root@9: '#default_value' => variable_get('smtp_username', ''), root@9: '#description' => t('SMTP Username.'), root@9: ); root@9: $form['auth']['smtp_password'] = array( root@9: '#type' => 'password', root@9: '#title' => t('Password'), root@9: '#default_value' => variable_get('smtp_password', ''), root@9: '#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: ); root@9: root@9: $form['email_options'] = array( root@9: '#type' => 'fieldset', root@9: '#title' => t('E-mail options'), root@9: ); root@9: $form['email_options']['smtp_from'] = array( root@9: '#type' => 'textfield', root@9: '#title' => t('E-mail from address'), root@9: '#default_value' => variable_get('smtp_from', ''), root@9: '#description' => t('The e-mail address that all e-mails will be from.'), root@9: ); root@9: $form['email_options']['smtp_fromname'] = array( root@9: '#type' => 'textfield', root@9: '#title' => t('E-mail from name'), root@9: '#default_value' => variable_get('smtp_fromname', ''), root@9: '#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: ); root@9: $form['email_options']['smtp_allowhtml'] = array( root@9: '#type' => 'checkbox', root@9: '#title' => t('Allow to send e-mails formated as Html'), root@9: '#default_value' => variable_get('smtp_allowhtml', 0), root@9: '#description' => t('Checking this box will allow Html formated e-mails to be sent with the SMTP protocol.'), root@9: ); root@9: root@9: // If an address was given, send a test e-mail message. root@9: $test_address = variable_get('smtp_test_address', ''); root@9: if ($test_address != '') { root@9: // Clear the variable so only one message is sent. root@9: variable_del('smtp_test_address'); root@9: global $language; root@9: $params['subject'] = t('Drupal SMTP test e-mail'); root@9: $params['body'] = array(t('If you receive this message it means your site is capable of using SMTP to send e-mail.')); root@9: drupal_mail('smtp', 'smtp-test', $test_address, $language, $params); root@9: 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: } root@9: $form['email_test'] = array( root@9: '#type' => 'fieldset', root@9: '#title' => t('Send test e-mail'), root@9: ); root@9: $form['email_test']['smtp_test_address'] = array( root@9: '#type' => 'textfield', root@9: '#title' => t('E-mail address to send a test e-mail to'), root@9: '#default_value' => '', root@9: '#description' => t('Type in an address to have a test e-mail sent there.'), root@9: ); root@9: root@9: $form['smtp_debugging'] = array( root@9: '#type' => 'checkbox', root@9: '#title' => t('Enable debugging'), root@9: '#default_value' => variable_get('smtp_debugging', 0), root@9: '#description' => t('Checking this box will print SMTP messages from the server for every e-mail that is sent.'), root@9: ); root@9: root@9: return system_settings_form($form); root@9: } // End of smtp_admin_settings(). root@9: root@9: root@9: root@9: /** root@9: * Validation for the administrative settings form. root@9: * root@9: * @param form root@9: * An associative array containing the structure of the form. root@9: * @param form_state root@9: * A keyed array containing the current state of the form. root@9: */ root@9: function smtp_admin_settings_validate($form, &$form_state) { root@9: if ($form_state['values']['smtp_on'] == 1 && $form_state['values']['smtp_host'] == '') { root@9: form_set_error('smtp_host', t('You must enter an SMTP server address.')); root@9: } root@9: root@9: if ($form_state['values']['smtp_on'] == 1 && $form_state['values']['smtp_port'] == '') { root@9: form_set_error('smtp_port', t('You must enter an SMTP port number.')); root@9: } root@9: root@9: if ($form_state['values']['smtp_from'] && !valid_email_address($form_state['values']['smtp_from'])) { root@9: form_set_error('smtp_from', t('The provided from e-mail address is not valid.')); root@9: } root@9: root@9: // If username is set empty, we must set both username/password empty as well. root@9: if (empty($form_state['values']['smtp_username'])) { root@9: $form_state['values']['smtp_password'] = ''; root@9: } root@9: root@9: // A little hack. When form is presentend, the password is not shown (Drupal way of doing). root@9: // So, if user submits the form without changing the password, we must prevent it from being reset. root@9: elseif (empty($form_state['values']['smtp_password'])) { root@9: unset($form_state['values']['smtp_password']); root@9: } root@9: } // End of smtp_admin_settings_validate(). root@9: