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