dolibarr 21.0.0-alpha
mails_emailing.php
1<?php
2/* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2016 Jonathan TISSEAU <jonathan.tisseau@86dev.fr>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
27// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
31
32// Load translation files required by the page
33$langs->loadLangs(array('companies', 'products', 'admin', 'mails', 'other', 'errors'));
34
35$action = GETPOST('action', 'aZ09');
36$cancel = GETPOST('cancel', 'aZ09');
37
38$usersignature = $user->signature;
39// For action = test or send, we ensure that content is not html, even for signature, because this we want a test with NO html.
40if ($action == 'test' || $action == 'send') {
41 $usersignature = dol_string_nohtmltag($usersignature, 2);
42}
43
44$substitutionarrayfortest = array(
45 '__ID__' => 'RecipientIdRecord',
46 '__USER_LOGIN__' => $user->login,
47 '__USER_EMAIL__' => $user->email,
48 '__USER_SIGNATURE__' => (($user->signature && !getDolGlobalString('MAIN_MAIL_DO_NOT_USE_SIGN')) ? $usersignature : ''), // Done into actions_sendmails
49 '__SENDEREMAIL_SIGNATURE__' => (($user->signature && !getDolGlobalString('MAIN_MAIL_DO_NOT_USE_SIGN')) ? $usersignature : ''), // Done into actions_sendmails
50 //'__EMAIL__' => 'RecipientEMail', // Done into actions_sendmails
51 '__LASTNAME__' => 'RecipientLastname',
52 '__FIRSTNAME__' => 'RecipientFirstname',
53 '__ADDRESS__' => 'RecipientAddress',
54 '__ZIP__' => 'RecipientZip',
55 '__TOWN_' => 'RecipientTown',
56 '__COUNTRY__' => 'RecipientCountry',
57 '__DOL_MAIN_URL_ROOT__' => DOL_MAIN_URL_ROOT,
58 '__CHECK_READ__' => '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag=undefinedtag&securitykey='.dol_hash(getDolGlobalString('MAILING_EMAIL_UNSUBSCRIBE_KEY')."-undefinedtag", 'md5').'" width="1" height="1" style="width:1px;height:1px" border="0"/>'
59);
60complete_substitutions_array($substitutionarrayfortest, $langs);
61
62// List of sending methods
63$listofmethods = array();
64$listofmethods['default'] = $langs->trans('DefaultOutgoingEmailSetup');
65$listofmethods['mail'] = 'PHP mail function';
66//$listofmethods['simplemail']='Simplemail class';
67$listofmethods['smtps'] = 'SMTP/SMTPS socket library';
68if (version_compare(phpversion(), '7.0', '>=')) {
69 $listofmethods['swiftmailer'] = 'Swift Mailer socket library';
70}
71
72// Security check
73if (!$user->admin) {
75}
76
77
78/*
79 * Actions
80 */
81
82if ($action == 'update' && !$cancel) {
83 // Send mode parameters
84 dolibarr_set_const($db, "MAIN_MAIL_SENDMODE_EMAILING", GETPOST("MAIN_MAIL_SENDMODE_EMAILING"), 'chaine', 0, '', $conf->entity);
85 dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT_EMAILING", GETPOST("MAIN_MAIL_SMTP_PORT_EMAILING"), 'chaine', 0, '', $conf->entity);
86 dolibarr_set_const($db, "MAIN_MAIL_SMTP_SERVER_EMAILING", GETPOST("MAIN_MAIL_SMTP_SERVER_EMAILING"), 'chaine', 0, '', $conf->entity);
87 dolibarr_set_const($db, "MAIN_MAIL_SMTPS_ID_EMAILING", GETPOST("MAIN_MAIL_SMTPS_ID_EMAILING"), 'chaine', 0, '', $conf->entity);
88 if (GETPOSTISSET("MAIN_MAIL_SMTPS_PW_EMAILING")) {
89 dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW_EMAILING", GETPOST("MAIN_MAIL_SMTPS_PW_EMAILING", 'password'), 'chaine', 0, '', $conf->entity);
90 }
91 if (GETPOSTISSET("MAIN_MAIL_SMTPS_AUTH_TYPE_EMAILING")) {
92 dolibarr_set_const($db, "MAIN_MAIL_SMTPS_AUTH_TYPE_EMAILING", GETPOST("MAIN_MAIL_SMTPS_AUTH_TYPE_EMAILING", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
93 }
94 if (GETPOSTISSET("MAIN_MAIL_SMTPS_OAUTH_SERVICE_EMAILING")) {
95 dolibarr_set_const($db, "MAIN_MAIL_SMTPS_OAUTH_SERVICE_EMAILING", GETPOST("MAIN_MAIL_SMTPS_OAUTH_SERVICE_EMAILING", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
96 }
97 dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS_EMAILING", GETPOST("MAIN_MAIL_EMAIL_TLS_EMAILING"), 'chaine', 0, '', $conf->entity);
98 dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS_EMAILING", GETPOST("MAIN_MAIL_EMAIL_STARTTLS_EMAILING"), 'chaine', 0, '', $conf->entity);
99 dolibarr_set_const($db, "MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING", GETPOST("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING"), 'chaine', 0, '', $conf->entity);
100
101 header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
102 exit;
103}
104
105
106// Actions to send emails
107$id = 0;
108$actiontypecode = ''; // Not an event for agenda
109$triggersendname = ''; // Disable triggers
110$paramname = 'id';
111$mode = 'emailfortest';
112$trackid = (($action == 'testhtml') ? "testhtml" : "test");
113$sendcontext = 'emailing'; // Force to use dedicated context of setup for emailing
114include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
115
116if ($action == 'presend' && GETPOST('trackid', 'alphanohtml') == 'test') {
117 $action = 'test';
118}
119if ($action == 'presend' && GETPOST('trackid', 'alphanohtml') == 'testhtml') {
120 $action = 'testhtml';
121}
122
123
124
125
126/*
127 * View
128 */
129
130$form = new Form($db);
131
132$linuxlike = 1;
133if (preg_match('/^win/i', PHP_OS)) {
134 $linuxlike = 0;
135}
136if (preg_match('/^mac/i', PHP_OS)) {
137 $linuxlike = 0;
138}
139
140if (!getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING')) {
141 $conf->global->MAIN_MAIL_SENDMODE_EMAILING = 'default';
142}
143$port = getDolGlobalInt('MAIN_MAIL_SMTP_PORT_EMAILING', (int) ini_get('smtp_port'));
144if (!$port) {
145 $port = 25;
146}
147$server = getDolGlobalString('MAIN_MAIL_SMTP_SERVER_EMAILING', ini_get('SMTP'));
148if (!$server) {
149 $server = '127.0.0.1';
150}
151
152
153$wikihelp = 'EN:Setup_EMails|FR:Paramétrage_EMails|ES:Configuración_EMails';
154llxHeader('', $langs->trans("Setup"), $wikihelp, '', 0, 0, '', '', '', 'mod-admin page-mails_emailing');
155
156print load_fiche_titre($langs->trans("EMailsSetup"), '', 'title_setup');
157
159
160// List of oauth services
161$oauthservices = array();
162
163foreach ($conf->global as $key => $val) {
164 if (!empty($val) && preg_match('/^OAUTH_.*_ID$/', $key)) {
165 $key = preg_replace('/^OAUTH_/', '', $key);
166 $key = preg_replace('/_ID$/', '', $key);
167 if (preg_match('/^.*-/', $key)) {
168 $name = preg_replace('/^.*-/', '', $key);
169 } else {
170 $name = $langs->trans("NoName");
171 }
172 $provider = preg_replace('/-.*$/', '', $key);
173 $provider = ucfirst(strtolower($provider));
174
175 $oauthservices[$key] = $name." (".$provider.")";
176 }
177}
178
179if ($action == 'edit') {
180 if ($conf->use_javascript_ajax) {
181 print "\n".'<script type="text/javascript">';
182 print 'jQuery(document).ready(function () {
183 function initfields()
184 {
185 if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'default\')
186 {
187 jQuery(".hideifdefault").hide();
188 }
189 else
190 {
191 jQuery(".hideifdefault").show();
192 }
193
194 if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'mail\')
195 {
196 console.log("I choose php mail mode");
197 jQuery(".drag").hide();
198 jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val(0);
199 jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").prop("disabled", true);
200 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val(0);
201 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").prop("disabled", true);
202 jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val(0);
203 jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").prop("disabled", true);
204 jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED_EMAILING").val(0);
205 jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED_EMAILING").prop("disabled", true);
206 jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN_EMAILING").prop("disabled", true);
207 jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR_EMAILING").prop("disabled", true);
208 jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY_EMAILING").prop("disabled", true);
209 jQuery(".smtp_method").hide();
210 jQuery(".dkim").hide();
211 jQuery(".smtp_auth_method").hide();
212 ';
213 if ($linuxlike) {
214 print '
215 jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").hide();
216 jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").hide();
217 jQuery("#smtp_server_mess").show();
218 jQuery("#smtp_port_mess").show();
219 ';
220 } else {
221 print '
222 jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").prop("disabled", true);
223 jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").prop("disabled", true);
224 jQuery("#smtp_server_mess").hide();
225 jQuery("#smtp_port_mess").hide();
226 ';
227 }
228 print '
229 }
230 if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'smtps\')
231 {
232 console.log("I choose smtps mail mode");
233 jQuery(".drag").show();
234 jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val(' . getDolGlobalString('MAIN_MAIL_EMAIL_TLS_EMAILING').');
235 jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").removeAttr("disabled");
236 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val(' . getDolGlobalString('MAIN_MAIL_EMAIL_STARTTLS_EMAILING').');
237 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").removeAttr("disabled");
238 jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val(' . getDolGlobalString('MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING').');
239 jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").removeAttr("disabled");
240 jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED_EMAILING").val(0);
241 jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED_EMAILING").prop("disabled", true);
242 jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN_EMAILING").prop("disabled", true);
243 jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR_EMAILING").prop("disabled", true);
244 jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY_EMAILING").prop("disabled", true);
245 jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN_EMAILING").hide();
246 jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR_EMAILING").hide();
247 jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY_EMAILING").hide();
248 jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").removeAttr("disabled");
249 jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").removeAttr("disabled");
250 jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").show();
251 jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").show();
252 jQuery("#smtp_port_mess").hide();
253 jQuery("#smtp_server_mess").hide();
254 jQuery(".smtp_method").show();
255 jQuery(".dkim").hide();
256 jQuery(".smtp_auth_method").show();
257 }
258 if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'swiftmailer\')
259 {
260 console.log("I choose swiftmailer mail mode");
261 jQuery(".drag").show();
262 jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val(' . getDolGlobalString('MAIN_MAIL_EMAIL_TLS_EMAILING').');
263 jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").removeAttr("disabled");
264 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val(' . getDolGlobalString('MAIN_MAIL_EMAIL_STARTTLS_EMAILING').');
265 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").removeAttr("disabled");
266 jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val(' . getDolGlobalString('MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING').');
267 jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").removeAttr("disabled");
268 jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED_EMAILING").val(0);
269 jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED_EMAILING").prop("disabled", true);
270 jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN_EMAILING").prop("disabled", true);
271 jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR_EMAILING").prop("disabled", true);
272 jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY_EMAILING").prop("disabled", true);
273 jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN_EMAILING").hide();
274 jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR_EMAILING").hide();
275 jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY_EMAILING").hide();
276 jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").removeAttr("disabled");
277 jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").removeAttr("disabled");
278 jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").show();
279 jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").show();
280 jQuery("#smtp_server_mess").hide();
281 jQuery("#smtp_port_mess").hide();
282 jQuery(".smtp_method").show();
283 jQuery(".dkim").show();
284 jQuery(".smtp_auth_method").show();
285 }
286 }
287 function change_smtp_auth_method() {
288 console.log("Call smtp auth method");
289 if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'smtps\') {
290 if (jQuery("#radio_oauth").prop("checked")) {
291 jQuery(".smtp_pw").hide();
292 jQuery(".smtp_oauth_service").show();
293 } else {
294 jQuery(".smtp_pw").show();
295 jQuery(".smtp_oauth_service").hide();
296 }
297 } else if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'swiftmailer\') {
298 if (jQuery("#radio_oauth").prop("checked")) {
299 jQuery(".smtp_pw").hide();
300 jQuery(".smtp_oauth_service").show();
301 } else {
302 jQuery(".smtp_pw").show();
303 jQuery(".smtp_oauth_service").hide();
304 }
305 } else {
306 jQuery(".smtp_pw").hide();
307 jQuery(".smtp_oauth_service").hide();
308 }
309 }
310
311 change_smtp_auth_method();
312 initfields();
313
314 jQuery("#MAIN_MAIL_SENDMODE_EMAILING").change(function() {
315 change_smtp_auth_method();
316 initfields();
317 });
318 jQuery("#radio_pw, #radio_plain, #radio_oauth").change(function() {
319 change_smtp_auth_method();
320 });
321 jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").change(function() {
322 if (jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val() == 1)
323 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val(0);
324 else
325 jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val(0);
326 });
327 jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").change(function() {
328 if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val() == 1)
329 jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val(0);
330 else
331 jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val(0);
332 });
333 })';
334 print '</script>'."\n";
335 }
336
337 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
338 print '<input type="hidden" name="token" value="'.newToken().'">';
339 print '<input type="hidden" name="action" value="update">';
340
341 print dol_get_fiche_head($head, 'common_emailing', '', -1);
342
343 print '<span class="opacitymedium">'.$langs->trans("EMailsDesc")."</span><br>\n";
344 print "<br><br>\n";
345
346
347 clearstatcache();
348
349 print '<table class="noborder centpercent">';
350 print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameters").'</td><td></td></tr>';
351
352 // Method
353
354 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
355
356 // SuperAdministrator access only
357 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
358 print $form->selectarray('MAIN_MAIL_SENDMODE_EMAILING', $listofmethods, $conf->global->MAIN_MAIL_SENDMODE_EMAILING);
359 } else {
360 $text = $listofmethods[getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING')];
361 if (empty($text)) {
362 $text = $langs->trans("Undefined");
363 }
364 $htmltext = $langs->trans("ContactSuperAdminForChange");
365 print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
366 print '<input type="hidden" name="MAIN_MAIL_SENDMODE_EMAILING" value="' . getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING').'">';
367 }
368 print '</td></tr>';
369
370 // Host server
371
372 print '<tr class="oddeven hideifdefault">';
373 if (!$conf->use_javascript_ajax && $linuxlike && getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') == 'mail') {
374 print '<td>';
375 print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
376 print '</td><td>';
377 print '<span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
378 print '</td>';
379 } else {
380 print '<td>';
381 $mainserver = (getDolGlobalString('MAIN_MAIL_SMTP_SERVER_EMAILING') ? $conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING : '');
382 $smtpserver = ini_get('SMTP') ? ini_get('SMTP') : $langs->transnoentities("Undefined");
383 if ($linuxlike) {
384 print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
385 } else {
386 print $langs->trans("MAIN_MAIL_SMTP_SERVER", $smtpserver);
387 }
388 print '</td><td>';
389 // SuperAdministrator access only
390 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
391 print '<input class="flat minwidth300" id="MAIN_MAIL_SMTP_SERVER_EMAILING" name="MAIN_MAIL_SMTP_SERVER_EMAILING" size="18" value="' . $mainserver . '">';
392 print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_EMAILING_sav" name="MAIN_MAIL_SMTP_SERVER_EMAILING_sav" value="' . $mainserver . '">';
393 print '<span id="smtp_server_mess" class="opacitymedium">' . $langs->trans("SeeLocalSendMailSetup") . '</span>';
394 print ' <span class="opacitymedium smtp_method">' . $langs->trans("SeeLinkToOnlineDocumentation") . '</span>';
395 } else {
396 $text = !empty($mainserver) ? $mainserver : $smtpserver;
397 $htmltext = $langs->trans("ContactSuperAdminForChange");
398 print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
399 print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_EMAILING" name="MAIN_MAIL_SMTP_SERVER_EMAILING" value="' . $mainserver . '">';
400 }
401 print '</td>';
402 }
403 print '</tr>';
404
405 // Port
406
407 print '<tr class="oddeven hideifdefault hideonmodemail"><td>';
408 if (!$conf->use_javascript_ajax && $linuxlike && getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') == 'mail') {
409 print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
410 print '</td><td>';
411 print '<span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
412 } else {
413 $mainport = (getDolGlobalString('MAIN_MAIL_SMTP_PORT_EMAILING') ? $conf->global->MAIN_MAIL_SMTP_PORT_EMAILING : '');
414 $smtpport = ini_get('smtp_port') ? ini_get('smtp_port') : $langs->transnoentities("Undefined");
415 if ($linuxlike) {
416 print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
417 } else {
418 print $langs->trans("MAIN_MAIL_SMTP_PORT", $smtpport);
419 }
420 print '</td><td>';
421 // SuperAdministrator access only
422 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
423 print '<input class="flat" id="MAIN_MAIL_SMTP_PORT_EMAILING" name="MAIN_MAIL_SMTP_PORT_EMAILING" size="3" value="' . $mainport . '">';
424 print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_EMAILING_sav" name="MAIN_MAIL_SMTP_PORT_EMAILING_sav" value="' . $mainport . '">';
425 print '<span id="smtp_port_mess" class="opacitymedium">' . $langs->trans("SeeLocalSendMailSetup") . '</span>';
426 } else {
427 $text = (!empty($mainport) ? $mainport : $smtpport);
428 $htmltext = $langs->trans("ContactSuperAdminForChange");
429 print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
430 print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_EMAILING" name="MAIN_MAIL_SMTP_PORT_EMAILING" value="' . $mainport . '">';
431 }
432 }
433 print '</td></tr>';
434
435 // AUTH method
436 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))) {
437 print '<tr class="oddeven smtp_auth_method hideonmodemail hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_AUTH_TYPE").'</td><td>';
438 $vartosmtpstype = 'MAIN_MAIL_SMTPS_AUTH_TYPE_EMAILING';
439 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
440 // Note: Default value for MAIN_MAIL_SMTPS_AUTH_TYPE if not defined is 'LOGIN' (but login/pass may be empty and they won't be provided in such a case)
441 print '<input type="radio" id="radio_pw" name="'.$vartosmtpstype.'" value="LOGIN"'.(getDolGlobalString($vartosmtpstype, 'LOGIN') == 'LOGIN' ? ' checked' : '').'> ';
442 print '<label for="radio_pw" >'.$langs->trans("UseAUTHLOGIN").'</label>';
443 print '<br>';
444 print '<input type="radio" id="radio_plain" name="'.$vartosmtpstype.'" value="PLAIN"'.(getDolGlobalString($vartosmtpstype, 'PLAIN') == 'PLAIN' ? ' checked' : '').'> ';
445 print '<label for="radio_plain" >'.$langs->trans("UseAUTHPLAIN").'</label>';
446 print '<br>';
447 print '<input type="radio" id="radio_oauth" name="'.$vartosmtpstype.'" value="XOAUTH2"'.(getDolGlobalString($vartosmtpstype) == 'XOAUTH2' ? ' checked' : '').(isModEnabled('oauth') ? '' : ' disabled').'> ';
448 print '<label for="radio_oauth" >'.$form->textwithpicto($langs->trans("UseOauth"), $langs->trans("OauthNotAvailableForAllAndHadToBeCreatedBefore")).'</label>';
449 if (!isModEnabled('oauth')) {
450 print ' &nbsp; <a href="'.DOL_URL_ROOT.'/admin/modules.php?search_keyword=oauth">'.$langs->trans("EnableModuleX", "OAuth").'</a>';
451 } else {
452 print ' &nbsp; <a href="'.DOL_URL_ROOT.'/admin/oauth.php">'.$langs->trans("SetupModuleX", " OAuth").'</a>';
453 }
454 } else {
455 $value = getDolGlobalString($vartosmtpstype, 'LOGIN');
456 $htmltext = $langs->trans("ContactSuperAdminForChange");
457 print $form->textwithpicto($langs->trans("MAIN_MAIL_SMTPS_AUTH_TYPE"), $htmltext, 1, 'superadmin');
458 print '<input type="hidden" id="MAIN_MAIL_SMTPS_AUTH_TYPE" name="MAIN_MAIL_SMTPS_AUTH_TYPE_EMAILING" value="'.$value.'">';
459 }
460 print '</td></tr>';
461 }
462
463 // ID
464 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))) {
465 $mainstmpid = (getDolGlobalString('MAIN_MAIL_SMTPS_ID_EMAILING') ? $conf->global->MAIN_MAIL_SMTPS_ID_EMAILING : '');
466 print '<tr class="drag drop oddeven hideifdefault"><td>' . $langs->trans("MAIN_MAIL_SMTPS_ID") . '</td><td>';
467 // SuperAdministrator access only
468 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
469 print '<input class="flat" name="MAIN_MAIL_SMTPS_ID_EMAILING" size="32" value="' . $mainstmpid . '">';
470 } else {
471 $htmltext = $langs->trans("ContactSuperAdminForChange");
472 print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_ID_EMAILING, $htmltext, 1, 'superadmin');
473 print '<input type="hidden" name="MAIN_MAIL_SMTPS_ID_EMAILING" value="' . $mainstmpid . '">';
474 }
475 print '</td></tr>';
476 }
477
478 // PW
479 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))) {
480 $mainsmtppw = getDolGlobalString('MAIN_MAIL_SMTPS_PW_EMAILING');
481 print '<tr class="drag drop oddeven smtp_pw hideifdefault"><td>' . $langs->trans("MAIN_MAIL_SMTPS_PW") . '</td><td>';
482 // SuperAdministrator access only
483 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
484 print '<input class="flat" type="password" name="MAIN_MAIL_SMTPS_PW_EMAILING" size="32" value="' . $mainsmtppw . '">';
485 } else {
486 $htmltext = $langs->trans("ContactSuperAdminForChange");
487 print $form->textwithpicto(getDolGlobalString('MAIN_MAIL_SMTPS_PW_EMAILING'), $htmltext, 1, 'superadmin');
488 print '<input type="hidden" name="MAIN_MAIL_SMTPS_PW_EMAILING" value="' . $mainsmtppw . '">';
489 }
490 print '</td></tr>';
491 }
492
493 // OAUTH service provider
494 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))) {
495 print '<tr class="oddeven smtp_oauth_service hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_OAUTH_SERVICE").'</td><td>';
496
497 // SuperAdministrator access only
498 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
499 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
500 print $form->selectarray('MAIN_MAIL_SMTPS_OAUTH_SERVICE_EMAILING', $oauthservices, $conf->global->MAIN_MAIL_SMTPS_OAUTH_SERVICE_EMAILING);
501 } else {
502 $text = $oauthservices[getDolGlobalString('MAIN_MAIL_SMTPS_OAUTH_SERVICE_EMAILING')];
503 if (empty($text)) {
504 $text = $langs->trans("Undefined");
505 }
506 $htmltext = $langs->trans("ContactSuperAdminForChange");
507 print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
508 print '<input type="hidden" name="MAIN_MAIL_SMTPS_OAUTH_SERVICE_EMAILING" value="' . getDolGlobalString('MAIN_MAIL_SMTPS_OAUTH_SERVICE_EMAILING').'">';
509 }
510 print '</td></tr>';
511 }
512
513
514 // TLS
515 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
516 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))) {
517 if (function_exists('openssl_open')) {
518 print $form->selectyesno('MAIN_MAIL_EMAIL_TLS_EMAILING', (getDolGlobalString('MAIN_MAIL_EMAIL_TLS_EMAILING') ? $conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING : 0), 1);
519 } else {
520 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
521 }
522 } else {
523 print yn(0).' ('.$langs->trans("NotSupported").')';
524 }
525 print '</td></tr>';
526
527 // STARTTLS
528 print '<tr class="oddeven hideifdefault hideonmodemail"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
529 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))) {
530 if (function_exists('openssl_open')) {
531 print $form->selectyesno('MAIN_MAIL_EMAIL_STARTTLS_EMAILING', (getDolGlobalString('MAIN_MAIL_EMAIL_STARTTLS_EMAILING') ? $conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING : 0), 1);
532 } else {
533 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
534 }
535 } else {
536 print yn(0).' ('.$langs->trans("NotSupported").')';
537 }
538 print '</td></tr>';
539
540 // SMTP_ALLOW_SELF_SIGNED_EMAILING
541 print '<tr class="oddeven hideifdefault hideonmodemail"><td>'.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").'</td><td>';
542 if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))) {
543 if (function_exists('openssl_open')) {
544 print $form->selectyesno('MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING', (getDolGlobalString('MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING') ? $conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING : 0), 1);
545 } else {
546 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
547 }
548 } else {
549 print yn(0).' ('.$langs->trans("NotSupported").')';
550 }
551 print '</td></tr>';
552
553 print '</table>';
554
555 print dol_get_fiche_end();
556
557 print $form->buttonsSaveCancel();
558
559 print '</form>';
560} else {
561 print dol_get_fiche_head($head, 'common_emailing', '', -1);
562
563 print '<span class="opacitymedium">'.$langs->trans("EMailsDesc")."</span><br>\n";
564 print "<br><br>\n";
565
566 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
567 print '<table class="noborder centpercent">';
568 print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameters").'</td><td></td></tr>';
569
570 // Method
571 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
572 $text = $listofmethods[getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING')];
573 if (empty($text)) {
574 $text = $langs->trans("Undefined").img_warning();
575 }
576 if (getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') == 'default') {
577 print '<span class="opacitymedium">'.$text.'</span>';
578 } else {
579 print $text;
580 }
581 print '</td></tr>';
582
583 if (getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') && getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') != 'default') {
584 // Host server
585 if ($linuxlike && (getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') == 'mail')) {
586 //print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
587 } else {
588 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER", ini_get('SMTP') ? ini_get('SMTP') : $langs->transnoentities("Undefined")).'</td><td>'.(getDolGlobalString('MAIN_MAIL_SMTP_SERVER_EMAILING') ? $conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING : '').'</td></tr>';
589 }
590
591 // Port
592 if ($linuxlike && (getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') == 'mail')) {
593 //print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
594 } else {
595 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT", ini_get('smtp_port') ? ini_get('smtp_port') : $langs->transnoentities("Undefined")).'</td><td>'.(getDolGlobalString('MAIN_MAIL_SMTP_PORT_EMAILING') ? $conf->global->MAIN_MAIL_SMTP_PORT_EMAILING : '').'</td></tr>';
596 }
597
598 // AUTH method
599 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING'), array('smtps', 'swiftmailer'))) {
600 $authtype = getDolGlobalString('MAIN_MAIL_SMTPS_AUTH_TYPE_EMAILING', 'LOGIN');
601 $text = '';
602 if ($authtype === "LOGIN") {
603 $text = $langs->trans("UseAUTHLOGIN");
604 } elseif ($authtype === "PLAIN") {
605 $text = $langs->trans("UseAUTHPLAIN");
606 } elseif ($authtype === "XOAUTH2") {
607 $text = $langs->trans("UseOauth");
608 }
609 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_AUTH_TYPE").'</td><td>'.$text.'</td></tr>';
610 }
611
612 // SMTPS ID
613 if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))) {
614 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>'.getDolGlobalString('MAIN_MAIL_SMTPS_ID_EMAILING').'</td></tr>';
615 }
616
617 // SMTPS PW
618 if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')) && getDolGlobalString('MAIN_MAIL_SMTPS_AUTH_TYPE_EMAILING') != "XOAUTH2") {
619 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>'.preg_replace('/./', '*', getDolGlobalString('MAIN_MAIL_SMTPS_PW_EMAILING')).'</td></tr>';
620 }
621
622 // SMTPS oauth service
623 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING'), array('smtps', 'swiftmailer')) && getDolGlobalString('MAIN_MAIL_SMTPS_AUTH_TYPE_EMAILING') === "XOAUTH2") {
624 $text = $oauthservices[getDolGlobalString('MAIN_MAIL_SMTPS_OAUTH_SERVICE_EMAILING')];
625 if (empty($text)) {
626 $text = $langs->trans("Undefined").img_warning();
627 }
628 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_OAUTH_SERVICE").'</td><td>'.$text.'</td></tr>';
629 }
630
631 // TLS
632 if ($linuxlike && (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail')) {
633 // Nothing
634 } else {
635 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
636 if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))) {
637 if (function_exists('openssl_open')) {
638 print yn(getDolGlobalString('MAIN_MAIL_EMAIL_TLS_EMAILING'));
639 } else {
640 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
641 }
642 } else {
643 print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
644 }
645 print '</td></tr>';
646 }
647
648 // STARTTLS
649 if ($linuxlike && (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail')) {
650 // Nothing
651 } else {
652 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
653 if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))) {
654 if (function_exists('openssl_open')) {
655 print yn(getDolGlobalString('MAIN_MAIL_EMAIL_STARTTLS_EMAILING'));
656 } else {
657 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
658 }
659 } else {
660 print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
661 }
662 print '</td></tr>';
663 }
664
665 // SMTP_ALLOW_SELF_SIGNED_EMAILING
666 if ($linuxlike && (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail')) {
667 // Nothing
668 } else {
669 print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").'</td><td>';
670 if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))) {
671 if (function_exists('openssl_open')) {
672 print yn(getDolGlobalInt('MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING'));
673 } else {
674 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
675 }
676 } else {
677 print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
678 }
679 print '</td></tr>';
680 }
681 }
682
683 print '</table>';
684 print '</div>';
685
686 print dol_get_fiche_end();
687
688
689 if (getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') == 'mail' && !getDolGlobalString('MAIN_FIX_FOR_BUGGED_MTA')) {
690 print '<br>';
691 /*
692 // Warning 1
693 if ($linuxlike) {
694 $sendmailoption=ini_get('mail.force_extra_parameters');
695 if (empty($sendmailoption) || ! preg_match('/ba/',$sendmailoption)) {
696 print info_admin($langs->trans("SendmailOptionNotComplete"));
697 }
698 }*/
699 // Warning 2
700 print info_admin($langs->trans("SendmailOptionMayHurtBuggedMTA"));
701 }
702
703
704 // Buttons for actions
705
706 print '<div class="tabsAction">';
707
708 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
709
710 if (getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') && getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') != 'default') {
711 if (getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') != 'mail' || !$linuxlike) {
712 if (function_exists('fsockopen') && $port && $server) {
713 print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=testconnect">' . $langs->trans("DoTestServerAvailability") . '</a>';
714 }
715 } else {
716 print '<a class="butActionRefused classfortooltip" href="#" title="' . $langs->trans("FeatureNotAvailableOnLinux") . '">' . $langs->trans("DoTestServerAvailability") . '</a>';
717 }
718
719 print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=test&amp;mode=init">' . $langs->trans("DoTestSend") . '</a>';
720
721 if (isModEnabled('fckeditor')) {
722 print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=testhtml&amp;mode=init">' . $langs->trans("DoTestSendHTML") . '</a>';
723 }
724 }
725
726 print '</div>';
727
728
729 if (getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') == 'mail' && !in_array($action, array('testconnect', 'test', 'testhtml'))) {
730 $text = $langs->trans("WarningPHPMail", $listofmethods['mail'], $listofmethods['smtps']);
731 print info_admin($text);
732 }
733
734 // Run the test to connect
735 if ($action == 'testconnect') {
736 print '<div id="formmailaftertstconnect" name="formmailaftertstconnect"></div>';
737 print load_fiche_titre($langs->trans("DoTestServerAvailability"));
738
739 include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
740 $mail = new CMailFile('', '', '', '', array(), array(), array(), '', '', 0, 0, '', '', '', $trackid, $sendcontext);
741
742 $result = $mail->check_server_port($server, $port);
743 if ($result) {
744 print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort", $server, $port).'</div>';
745 } else {
746 $errormsg = $langs->trans("ServerNotAvailableOnIPOrPort", $server, $port);
747
748 if ($mail->error) {
749 $errormsg .= ' - '.$mail->error;
750 }
751
752 setEventMessages($errormsg, null, 'errors');
753 }
754 print '<br>';
755 }
756
757 // Show email send test form
758 if ($action == 'test' || $action == 'testhtml') {
759 print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
760 print load_fiche_titre($action == 'testhtml' ? $langs->trans("DoTestSendHTML") : $langs->trans("DoTestSend"));
761
762 print dol_get_fiche_head(array(), '', '', -1);
763
764 // Cree l'objet formulaire mail
765 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
766 $formmail = new FormMail($db);
767 $formmail->trackid = (($action == 'testhtml') ? "testhtml" : "test");
768 $formmail->fromname = (GETPOSTISSET('fromname') ? GETPOST('fromname', 'restricthtml') : $conf->global->MAIN_MAIL_EMAIL_FROM);
769 $formmail->frommail = (GETPOSTISSET('frommail') ? GETPOST('frommail', 'restricthtml') : $conf->global->MAIN_MAIL_EMAIL_FROM);
770 $formmail->fromid = $user->id;
771 $formmail->fromalsorobot = 1;
772 $formmail->withfromreadonly = 0;
773 $formmail->withsubstit = 0;
774 $formmail->withfrom = 1;
775 $formmail->witherrorsto = 1;
776 $formmail->withto = (GETPOSTISSET('sendto') ? GETPOST('sendto', 'restricthtml') : ($user->email ? $user->email : 1));
777 $formmail->withtocc = (GETPOSTISSET('sendtocc') ? GETPOST('sendtocc', 'restricthtml') : 1); // ! empty to keep field if empty
778 $formmail->withtoccc = (GETPOSTISSET('sendtoccc') ? GETPOST('sendtoccc', 'restricthtml') : 1); // ! empty to keep field if empty
779 $formmail->withtopic = (GETPOSTISSET('subject') ? GETPOST('subject') : $langs->trans("Test"));
780 $formmail->withtopicreadonly = 0;
781 $formmail->withfile = 2;
782 $formmail->withbody = (GETPOSTISSET('message') ? GETPOST('message', 'restricthtml') : ($action == 'testhtml' ? $langs->transnoentities("PredefinedMailTestHtml") : $langs->transnoentities("PredefinedMailTest")));
783 $formmail->withbodyreadonly = 0;
784 $formmail->withcancel = 1;
785 $formmail->withdeliveryreceipt = 1;
786 $formmail->withfckeditor = ($action == 'testhtml' ? 1 : 0);
787 $formmail->ckeditortoolbar = 'dolibarr_mailings';
788 // Tableau des substitutions
789 $formmail->substit = $substitutionarrayfortest;
790 // Tableau des parameters complementaires du post
791 $formmail->param["action"] = "send";
792 $formmail->param["models"] = "body";
793 $formmail->param["mailid"] = 0;
794 $formmail->param["returnurl"] = $_SERVER["PHP_SELF"];
795
796 // Init list of files
797 if (GETPOST("mode", "aZ09") == 'init') {
798 $formmail->clear_attached_files();
799 }
800
801 print $formmail->get_form('addfile', 'removefile');
802
803 print dol_get_fiche_end();
804 }
805}
806
807// End of page
808llxFooter();
809$db->close();
$id
Definition account.php:39
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
email_admin_prepare_head()
Return array head with list of tabs to view object information.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new Form...
llxFooter()
Footer empty.
Definition document.php:107
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.