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