dolibarr 21.0.3
mails.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2020 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) 2023 Anthony Berton <anthony.berton@bb2a.fr>
7 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
29// Load Dolibarr environment
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
34
44// Load translation files required by the page
45$langs->loadLangs(array("companies", "products", "admin", "mails", "other", "errors"));
46
47$action = GETPOST('action', 'aZ09');
48$cancel = GETPOST('cancel', 'aZ09');
49
50$trackid = GETPOST('trackid');
51
52if (!$user->admin) {
54}
55
56$usersignature = $user->signature;
57// For action = test or send, we ensure that content is not html, even for signature, because for this we want a test with NO html.
58if ($action == 'test' || ($action == 'send' && $trackid == 'test')) {
59 $usersignature = dol_string_nohtmltag($usersignature, 2);
60}
61
62$substitutionarrayfortest = array(
63 '__USER_LOGIN__' => $user->login,
64 '__USER_EMAIL__' => $user->email,
65 '__USER_FIRSTNAME__' => $user->firstname,
66 '__USER_LASTNAME__' => $user->lastname,
67 '__USER_SIGNATURE__' => (($user->signature && !getDolGlobalString('MAIN_MAIL_DO_NOT_USE_SIGN')) ? $usersignature : ''), // Done into actions_sendmails
68 '__SENDEREMAIL_SIGNATURE__' => (($user->signature && !getDolGlobalString('MAIN_MAIL_DO_NOT_USE_SIGN')) ? $usersignature : ''), // Done into actions_sendmails
69 //'__ID__' => 'RecipientID',
70 //'__EMAIL__' => 'RecipientEMail', // Done into actions_sendmails
71 '__LASTNAME__' => $langs->trans("Lastname").' ('.$langs->trans("Recipient").')',
72 '__FIRSTNAME__' => $langs->trans("Firstname").' ('.$langs->trans("Recipient").')',
73 //'__ADDRESS__'=> $langs->trans("Address").' ('.$langs->trans("Recipient").')',
74 //'__ZIP__'=> $langs->trans("Zip").' ('.$langs->trans("Recipient").')',
75 //'__TOWN_'=> $langs->trans("Town").' ('.$langs->trans("Recipient").')',
76 //'__COUNTRY__'=> $langs->trans("Country").' ('.$langs->trans("Recipient").')',
77 '__DOL_MAIN_URL_ROOT__' => DOL_MAIN_URL_ROOT,
78 '__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" />',
79);
80complete_substitutions_array($substitutionarrayfortest, $langs);
81
82
83
84/*
85 * Actions
86 */
87$error = 0;
88
89if ($action == 'update' && !$cancel) {
90 if (!GETPOST("MAIN_MAIL_EMAIL_FROM", 'alphanohtml')) {
91 $error++;
92 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("MAIN_MAIL_EMAIL_FROM")), null, 'errors');
93 $action = 'edit';
94 }
95 if (!$error && !isValidEmail(GETPOST("MAIN_MAIL_EMAIL_FROM", 'alphanohtml'))) {
96 $error++;
97 setEventMessages($langs->trans("ErrorBadEMail", GETPOST("MAIN_MAIL_EMAIL_FROM", 'alphanohtml')), null, 'errors');
98 $action = 'edit';
99 }
100
101 if (!$error) {
102 dolibarr_set_const($db, "MAIN_DISABLE_ALL_MAILS", GETPOSTINT("MAIN_DISABLE_ALL_MAILS"), 'chaine', 0, '', $conf->entity);
103 dolibarr_set_const($db, "MAIN_MAIL_FORCE_SENDTO", GETPOST("MAIN_MAIL_FORCE_SENDTO", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
104 dolibarr_set_const($db, "MAIN_MAIL_ENABLED_USER_DEST_SELECT", GETPOSTINT("MAIN_MAIL_ENABLED_USER_DEST_SELECT"), 'chaine', 0, '', $conf->entity);
105 dolibarr_set_const($db, 'MAIN_MAIL_NO_WITH_TO_SELECTED', GETPOSTINT('MAIN_MAIL_NO_WITH_TO_SELECTED'), 'chaine', 0, '', $conf->entity);
106 // Send mode parameters
107 dolibarr_set_const($db, "MAIN_MAIL_SENDMODE", GETPOST("MAIN_MAIL_SENDMODE", 'aZ09'), 'chaine', 0, '', $conf->entity);
108 dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT", GETPOSTINT("MAIN_MAIL_SMTP_PORT"), 'chaine', 0, '', $conf->entity);
109 dolibarr_set_const($db, "MAIN_MAIL_SMTP_SERVER", GETPOST("MAIN_MAIL_SMTP_SERVER", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
110 dolibarr_set_const($db, "MAIN_MAIL_SMTPS_ID", GETPOST("MAIN_MAIL_SMTPS_ID", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
111 if (GETPOSTISSET("MAIN_MAIL_SMTPS_PW")) {
112 dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW", GETPOST("MAIN_MAIL_SMTPS_PW", 'password'), 'chaine', 0, '', $conf->entity);
113 }
114 if (GETPOSTISSET("MAIN_MAIL_SMTPS_AUTH_TYPE")) {
115 dolibarr_set_const($db, "MAIN_MAIL_SMTPS_AUTH_TYPE", GETPOST("MAIN_MAIL_SMTPS_AUTH_TYPE", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
116 }
117 if (GETPOSTISSET("MAIN_MAIL_SMTPS_OAUTH_SERVICE")) {
118 dolibarr_set_const($db, "MAIN_MAIL_SMTPS_OAUTH_SERVICE", GETPOST("MAIN_MAIL_SMTPS_OAUTH_SERVICE", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
119 }
120 dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS", GETPOSTINT("MAIN_MAIL_EMAIL_TLS"), 'chaine', 0, '', $conf->entity);
121 dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS", GETPOSTINT("MAIN_MAIL_EMAIL_STARTTLS"), 'chaine', 0, '', $conf->entity);
122 dolibarr_set_const($db, "MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED", GETPOSTINT("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED"), 'chaine', 0, '', $conf->entity);
123
124 dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_ENABLED", GETPOSTINT("MAIN_MAIL_EMAIL_DKIM_ENABLED"), 'chaine', 0, '', $conf->entity);
125 dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_DOMAIN", GETPOST("MAIN_MAIL_EMAIL_DKIM_DOMAIN", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
126 dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_SELECTOR", GETPOST("MAIN_MAIL_EMAIL_DKIM_SELECTOR", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
127 dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY", GETPOST("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
128 // Content parameters
129 dolibarr_set_const($db, "MAIN_MAIL_EMAIL_FROM", GETPOST("MAIN_MAIL_EMAIL_FROM", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
130 dolibarr_set_const($db, "MAIN_MAIL_ERRORS_TO", GETPOST("MAIN_MAIL_ERRORS_TO", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
131 dolibarr_set_const($db, "MAIN_MAIL_AUTOCOPY_TO", GETPOST("MAIN_MAIL_AUTOCOPY_TO", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
132 dolibarr_set_const($db, 'MAIN_MAIL_DEFAULT_FROMTYPE', GETPOST('MAIN_MAIL_DEFAULT_FROMTYPE', 'alphanohtml'), 'chaine', 0, '', $conf->entity);
133
134
135 header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
136 exit;
137 }
138}
139
140if ($action == 'disablephpmailwarning' && !$cancel) {
141 dolibarr_set_const($db, 'MAIN_HIDE_WARNING_TO_ENCOURAGE_SMTP_SETUP', 1, 'chaine', 1, '', $conf->entity);
142
143 setEventMessages($langs->trans("WarningDisabled"), null, 'mesgs');
144}
145
146// Actions to send emails
147$id = 0;
148$actiontypecode = ''; // Not an event for agenda
149$triggersendname = ''; // Disable triggers
150$paramname = 'id';
151$mode = 'emailfortest';
152$trackid = ($action == 'send' ? GETPOST('trackid', 'aZ09') : $action);
153$sendcontext = 'standard';
154include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
155
156if ($action == 'presend' && GETPOST('trackid', 'alphanohtml') == 'test') {
157 $action = 'test';
158}
159if ($action == 'presend' && GETPOST('trackid', 'alphanohtml') == 'testhtml') {
160 $action = 'testhtml';
161}
162
163
164/*
165 * View
166 */
167
168$form = new Form($db);
169
170// Set default variables
171$linuxlike = 1;
172if (preg_match('/^win/i', PHP_OS)) {
173 $linuxlike = 0;
174}
175if (preg_match('/^mac/i', PHP_OS)) {
176 $linuxlike = 0;
177}
178
179if (!getDolGlobalString('MAIN_MAIL_SENDMODE')) {
180 $conf->global->MAIN_MAIL_SENDMODE = 'mail';
181}
182
183$port = getDolGlobalInt('MAIN_MAIL_SMTP_PORT', (int) ini_get('smtp_port'));
184if (!$port) {
185 $port = 25;
186}
187$server = getDolGlobalString('MAIN_MAIL_SMTP_SERVER', ini_get('SMTP'));
188if (!$server) {
189 $server = '127.0.0.1';
190}
191
192
193$wikihelp = 'EN:Setup_EMails|FR:Paramétrage_EMails|ES:Configuración_EMails';
194llxHeader('', $langs->trans("Setup"), $wikihelp, '', 0, 0, '', '', '', 'mod-admin page-mails');
195
196print load_fiche_titre($langs->trans("EMailsSetup"), '', 'title_setup');
197
199
200// List of sending methods
201$listofmethods = array();
202$listofmethods['mail'] = 'PHP mail function';
203$listofmethods['smtps'] = 'SMTP/SMTPS socket library';
204if (version_compare(phpversion(), '7.0', '>=')) {
205 $listofmethods['swiftmailer'] = 'Swift Mailer socket library';
206}
207
208// List of oauth services
209$oauthservices = array();
210
211foreach ($conf->global as $key => $val) {
212 if (!empty($val) && preg_match('/^OAUTH_.*_ID$/', $key)) {
213 $key = preg_replace('/^OAUTH_/', '', $key);
214 $key = preg_replace('/_ID$/', '', $key);
215 if (preg_match('/^.*-/', $key)) {
216 $name = preg_replace('/^.*-/', '', $key);
217 } else {
218 $name = $langs->trans("NoName");
219 }
220 $provider = preg_replace('/-.*$/', '', $key);
221 $provider = ucfirst(strtolower($provider));
222
223 $oauthservices[$key] = $name." (".$provider.")";
224 }
225}
226
227if ($action == 'edit') {
228 if ($conf->use_javascript_ajax) {
229 print "\n".'<script type="text/javascript">';
230 print 'jQuery(document).ready(function () {
231 function initfields()
232 {
233 if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'mail\')
234 {
235 console.log("I choose php mail mode");
236 jQuery(".drag").hide();
237 jQuery("#MAIN_MAIL_EMAIL_TLS").val(0);
238 jQuery("#MAIN_MAIL_EMAIL_TLS").prop("disabled", true);
239 jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val(0);
240 jQuery("#MAIN_MAIL_EMAIL_STARTTLS").prop("disabled", true);
241 jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val(0);
242 jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").prop("disabled", true);
243 jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val(0);
244 jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").prop("disabled", true);
245 jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").prop("disabled", true);
246 jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").prop("disabled", true);
247 jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").prop("disabled", true);
248 jQuery(".smtp_method").hide();
249 jQuery(".dkim").hide();
250 jQuery(".smtp_auth_method").hide();
251 ';
252 if ($linuxlike) {
253 print '
254 jQuery("#MAIN_MAIL_SMTP_SERVER").hide();
255 jQuery("#MAIN_MAIL_SMTP_PORT").hide();
256 jQuery("#smtp_server_mess").show();
257 jQuery("#smtp_port_mess").show();';
258 } else {
259 print '
260 jQuery("#MAIN_MAIL_SMTP_SERVER").prop("disabled", true);
261 jQuery("#MAIN_MAIL_SMTP_PORT").prop("disabled", true);
262 jQuery("#smtp_server_mess").hide();
263 jQuery("#smtp_port_mess").hide();';
264 }
265 print '
266 }
267 if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'smtps\')
268 {
269 console.log("I choose smtps mode");
270 jQuery(".drag").show();
271 jQuery("#MAIN_MAIL_EMAIL_TLS").val(' . getDolGlobalString('MAIN_MAIL_EMAIL_TLS').');
272 jQuery("#MAIN_MAIL_EMAIL_TLS").removeAttr("disabled");
273 jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val(' . getDolGlobalString('MAIN_MAIL_EMAIL_STARTTLS').');
274 jQuery("#MAIN_MAIL_EMAIL_STARTTLS").removeAttr("disabled");
275 jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val(' . getDolGlobalString('MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED').');
276 jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").removeAttr("disabled");
277 jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val(0);
278 jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").prop("disabled", true);
279 jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").prop("disabled", true);
280 jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").prop("disabled", true);
281 jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").prop("disabled", true);
282 jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").hide();
283 jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").hide();
284 jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").hide();
285 jQuery("#MAIN_MAIL_SMTP_SERVER").removeAttr("disabled");
286 jQuery("#MAIN_MAIL_SMTP_PORT").removeAttr("disabled");
287 jQuery("#MAIN_MAIL_SMTP_SERVER").show();
288 jQuery("#MAIN_MAIL_SMTP_PORT").show();
289 jQuery("#smtp_server_mess").hide();
290 jQuery("#smtp_port_mess").hide();
291 jQuery(".smtp_method").show();
292 jQuery(".dkim").hide();
293 jQuery(".smtp_auth_method").show();
294 }
295 if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'swiftmailer\')
296 {
297 console.log("I choose swiftmailer mode");
298 jQuery(".drag").show();
299 jQuery("#MAIN_MAIL_EMAIL_TLS").val(' . getDolGlobalString('MAIN_MAIL_EMAIL_TLS').');
300 jQuery("#MAIN_MAIL_EMAIL_TLS").removeAttr("disabled");
301 jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val(' . getDolGlobalString('MAIN_MAIL_EMAIL_STARTTLS').');
302 jQuery("#MAIN_MAIL_EMAIL_STARTTLS").removeAttr("disabled");
303 jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val(' . getDolGlobalString('MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED').');
304 jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").removeAttr("disabled");
305 jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val(' . getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_ENABLED').');
306 jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").removeAttr("disabled");
307 jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").removeAttr("disabled");
308 jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").removeAttr("disabled");
309 jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").removeAttr("disabled");
310 jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").show();
311 jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").show();
312 jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").show();
313 jQuery("#MAIN_MAIL_SMTP_SERVER").removeAttr("disabled");
314 jQuery("#MAIN_MAIL_SMTP_PORT").removeAttr("disabled");
315 jQuery("#MAIN_MAIL_SMTP_SERVER").show();
316 jQuery("#MAIN_MAIL_SMTP_PORT").show();
317 jQuery("#smtp_server_mess").hide();
318 jQuery("#smtp_port_mess").hide();
319 jQuery(".smtp_method").show();
320 jQuery(".dkim").show();
321 jQuery(".smtp_auth_method").show();
322 }
323 }
324 function change_smtp_auth_method() {
325 console.log("Call smtp auth method");
326 if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'smtps\') {
327 if (jQuery("#radio_oauth").prop("checked")) {
328 jQuery(".smtp_pw").hide();
329 jQuery(".smtp_oauth_service").show();
330 } else {
331 jQuery(".smtp_pw").show();
332 jQuery(".smtp_oauth_service").hide();
333 }
334 } else if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'swiftmailer\') {
335 if (jQuery("#radio_oauth").prop("checked")) {
336 jQuery(".smtp_pw").hide();
337 jQuery(".smtp_oauth_service").show();
338 } else {
339 jQuery(".smtp_pw").show();
340 jQuery(".smtp_oauth_service").hide();
341 }
342 } else {
343 jQuery(".smtp_pw").show();
344 jQuery(".smtp_oauth_service").hide();
345 }
346 }
347 initfields();
348 change_smtp_auth_method();
349 jQuery("#MAIN_MAIL_SENDMODE").change(function() {
350 initfields();
351 change_smtp_auth_method();
352 });
353 jQuery("#radio_pw, #radio_plain, #radio_oauth").change(function() {
354 change_smtp_auth_method();
355 });
356 jQuery("#MAIN_MAIL_EMAIL_TLS").change(function() {
357 if (jQuery("#MAIN_MAIL_EMAIL_TLS").val() == 1)
358 jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val(0);
359 else
360 jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val(0);
361 });
362 jQuery("#MAIN_MAIL_EMAIL_STARTTLS").change(function() {
363 if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val() == 1)
364 jQuery("#MAIN_MAIL_EMAIL_TLS").val(0);
365 else
366 jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val(0);
367 });
368 })';
369 print '</script>'."\n";
370 }
371
372 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
373 print '<input type="hidden" name="token" value="'.newToken().'">';
374 print '<input type="hidden" name="action" value="update">';
375
376 print dol_get_fiche_head($head, 'common', '', -1);
377
378 print '<span class="opacitymedium">'.$langs->trans("EMailsDesc")."</span><br>\n";
379 print "<br><br>\n";
380
381
382 clearstatcache();
383
384
385 print '<table class="noborder centpercent">';
386 print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameters").'</td><td></td></tr>';
387
388 // Method
389 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
390
391 // SuperAdministrator access only
392 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
393 print $form->selectarray('MAIN_MAIL_SENDMODE', $listofmethods, getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'));
394 } else {
395 $text = $listofmethods[getDolGlobalString('MAIN_MAIL_SENDMODE')];
396 if (empty($text)) {
397 $text = $langs->trans("Undefined");
398 }
399 $htmltext = $langs->trans("ContactSuperAdminForChange");
400 print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
401 print '<input type="hidden" name="MAIN_MAIL_SENDMODE" value="'.getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail').'">';
402 }
403 print '</td></tr>';
404
405 // Host server
406 print '<tr class="oddeven hideonmodemail">';
407 if (!$conf->use_javascript_ajax && $linuxlike && getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail') {
408 print '<td>';
409 print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
410 print '</td><td>';
411 print '<span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
412 print '</td>';
413 } else {
414 print '<td>';
415 $mainserver = getDolGlobalString('MAIN_MAIL_SMTP_SERVER');
416 $smtpserver = ini_get('SMTP') ? ini_get('SMTP') : $langs->transnoentities("Undefined");
417 if ($linuxlike) {
418 print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
419 } else {
420 print $langs->trans("MAIN_MAIL_SMTP_SERVER", $smtpserver);
421 }
422 print '</td><td>';
423 // SuperAdministrator access only
424 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
425 print '<input class="flat minwidth300" id="MAIN_MAIL_SMTP_SERVER" name="MAIN_MAIL_SMTP_SERVER" value="'.$mainserver.'" autocomplete="off">';
426 print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_sav" name="MAIN_MAIL_SMTP_SERVER_sav" value="'.$mainserver.'">';
427 print '<span id="smtp_server_mess" class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
428 print ' <span class="opacitymedium smtp_method">'.$langs->trans("SeeLinkToOnlineDocumentation").'</span>';
429 } else {
430 $text = !empty($mainserver) ? $mainserver : $smtpserver;
431 $htmltext = $langs->trans("ContactSuperAdminForChange");
432 print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
433 print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER" name="MAIN_MAIL_SMTP_SERVER" value="'.$mainserver.'">';
434 }
435 print '</td>';
436 }
437 print '</tr>';
438
439 // Port
440 print '<tr class="oddeven hideonmodemail"><td>';
441 if (!$conf->use_javascript_ajax && $linuxlike && getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail') {
442 print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
443 print '</td><td>';
444 print '<span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
445 } else {
446 $mainport = getDolGlobalString('MAIN_MAIL_SMTP_PORT');
447 $smtpport = ini_get('smtp_port') ? ini_get('smtp_port') : $langs->transnoentities("Undefined");
448 if ($linuxlike) {
449 print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
450 } else {
451 print $langs->trans("MAIN_MAIL_SMTP_PORT", $smtpport);
452 }
453 print '</td><td>';
454 // SuperAdministrator access only
455 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
456 print '<input class="flat" id="MAIN_MAIL_SMTP_PORT" name="MAIN_MAIL_SMTP_PORT" size="3" value="'.$mainport.'">';
457 print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_sav" name="MAIN_MAIL_SMTP_PORT_sav" value="'.$mainport.'">';
458 print '<span id="smtp_port_mess" class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
459 } else {
460 $text = (!empty($mainport) ? $mainport : $smtpport);
461 $htmltext = $langs->trans("ContactSuperAdminForChange");
462 print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
463 print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT" name="MAIN_MAIL_SMTP_PORT" value="'.$mainport.'">';
464 }
465 }
466 print '</td></tr>';
467
468 // Auth mode
469 if (!empty($conf->use_javascript_ajax) || (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer')))) {
470 print '<tr class="oddeven smtp_auth_method"><td>'.$langs->trans("MAIN_MAIL_SMTPS_AUTH_TYPE").'</td><td>';
471 $vartosmtpstype = 'MAIN_MAIL_SMTPS_AUTH_TYPE';
472 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
473 // 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)
474 print '<input type="radio" id="radio_none" name="'.$vartosmtpstype.'" value="NONE"'.(getDolGlobalString($vartosmtpstype) == 'NONE' ? ' checked' : '').'> ';
475 print '<label for="radio_none" >'.$langs->trans("UseAUTHNONE").'</label>';
476 print '<br>';
477 print '<input type="radio" id="radio_pw" name="'.$vartosmtpstype.'" value="LOGIN"'.(getDolGlobalString($vartosmtpstype, 'LOGIN') == 'LOGIN' ? ' checked' : '').'> ';
478 print '<label for="radio_pw" >'.$langs->trans("UseAUTHLOGIN").'</label>';
479 print '<br>';
480 print '<input type="radio" id="radio_plain" name="'.$vartosmtpstype.'" value="PLAIN"'.(getDolGlobalString($vartosmtpstype) == 'PLAIN' ? ' checked' : '').'> ';
481 print '<label for="radio_plain" >'.$langs->trans("UseAUTHPLAIN").'</label>';
482 print '<br>';
483 print '<input type="radio" id="radio_oauth" name="'.$vartosmtpstype.'" value="XOAUTH2"'.(getDolGlobalString($vartosmtpstype) == 'XOAUTH2' ? ' checked' : '').(isModEnabled('oauth') ? '' : ' disabled').'> ';
484 print '<label for="radio_oauth" >'.$form->textwithpicto($langs->trans("UseOauth"), $langs->trans("OauthNotAvailableForAllAndHadToBeCreatedBefore")).'</label>';
485 if (!isModEnabled('oauth')) {
486 print ' &nbsp; <a href="'.DOL_URL_ROOT.'/admin/modules.php?search_keyword=oauth">'.$langs->trans("EnableModuleX", "OAuth").'</a>';
487 } else {
488 print ' &nbsp; <a href="'.DOL_URL_ROOT.'/admin/oauth.php">'.$langs->trans("SetupModuleX", " OAuth").'</a>';
489 }
490 } else {
491 $value = getDolGlobalString($vartosmtpstype, 'LOGIN');
492 $htmltext = $langs->trans("ContactSuperAdminForChange");
493 print $form->textwithpicto($langs->trans("MAIN_MAIL_SMTPS_AUTH_TYPE"), $htmltext, 1, 'superadmin');
494 print '<input type="hidden" id="MAIN_MAIL_SMTPS_AUTH_TYPE" name="MAIN_MAIL_SMTPS_AUTH_TYPE" value="'.$value.'">';
495 }
496 print '</td></tr>';
497 }
498
499 // ID
500 if (!empty($conf->use_javascript_ajax) || (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer')))) {
501 $mainstmpid = getDolGlobalString('MAIN_MAIL_SMTPS_ID');
502 print '<tr class="drag drop oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>';
503 // SuperAdministrator access only
504 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
505 print '<input class="flat" name="MAIN_MAIL_SMTPS_ID" size="32" value="'.$mainstmpid.'">';
506 } else {
507 $htmltext = $langs->trans("ContactSuperAdminForChange");
508 print $form->textwithpicto(getDolGlobalString('MAIN_MAIL_SMTPS_ID'), $htmltext, 1, 'superadmin');
509 print '<input type="hidden" name="MAIN_MAIL_SMTPS_ID" value="'.$mainstmpid.'">';
510 }
511 print '</td></tr>';
512 }
513
514
515 // PW
516 if (!empty($conf->use_javascript_ajax) || (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer')))) {
517 $mainsmtppw = getDolGlobalString('MAIN_MAIL_SMTPS_PW');
518 print '<tr class="drag drop oddeven smtp_pw"><td>';
519 print $form->textwithpicto($langs->trans("MAIN_MAIL_SMTPS_PW"), $langs->trans("WithGMailYouCanCreateADedicatedPassword"));
520 print '</td><td>';
521 // SuperAdministrator access only
522 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
523 print '<input class="flat" type="password" name="MAIN_MAIL_SMTPS_PW" size="32" value="' . htmlspecialchars($mainsmtppw, ENT_COMPAT, 'UTF-8') . '" autocomplete="off">';
524 } else {
525 $htmltext = $langs->trans("ContactSuperAdminForChange");
526 print $form->textwithpicto(getDolGlobalString('MAIN_MAIL_SMTPS_PW'), $htmltext, 1, 'superadmin');
527 print '<input type="hidden" name="MAIN_MAIL_SMTPS_PW" value="' . htmlspecialchars($mainsmtppw, ENT_COMPAT, 'UTF-8') . '">';
528 }
529 print '</td></tr>';
530 }
531
532 // OAUTH service provider
533 if (!empty($conf->use_javascript_ajax) || (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer')))) {
534 print '<tr class="oddeven smtp_oauth_service"><td>'.$langs->trans("MAIN_MAIL_SMTPS_OAUTH_SERVICE").'</td><td>';
535
536 // SuperAdministrator access only
537 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
538 print $form->selectarray('MAIN_MAIL_SMTPS_OAUTH_SERVICE', $oauthservices, getDolGlobalString('MAIN_MAIL_SMTPS_OAUTH_SERVICE'));
539 } else {
540 $text = $oauthservices[getDolGlobalString('MAIN_MAIL_SMTPS_OAUTH_SERVICE')];
541 if (empty($text)) {
542 $text = $langs->trans("Undefined");
543 }
544 $htmltext = $langs->trans("ContactSuperAdminForChange");
545 print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
546 print '<input type="hidden" name="MAIN_MAIL_SMTPS_OAUTH_SERVICE" value="' . getDolGlobalString('MAIN_MAIL_SMTPS_OAUTH_SERVICE').'">';
547 }
548 print '</td></tr>';
549 }
550
551 // TLS
552 print '<tr class="oddeven hideonmodemail"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
553 if (!empty($conf->use_javascript_ajax) || (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer')))) {
554 if (function_exists('openssl_open')) {
555 print $form->selectyesno('MAIN_MAIL_EMAIL_TLS', (getDolGlobalString('MAIN_MAIL_EMAIL_TLS') ? getDolGlobalString('MAIN_MAIL_EMAIL_TLS') : 0), 1);
556 } else {
557 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
558 }
559 } else {
560 print yn(0).' ('.$langs->trans("NotSupported").')';
561 }
562 print '</td></tr>';
563
564 // STARTTLS
565 print '<tr class="oddeven hideonmodemail"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
566 if (!empty($conf->use_javascript_ajax) || (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer')))) {
567 if (function_exists('openssl_open')) {
568 print $form->selectyesno('MAIN_MAIL_EMAIL_STARTTLS', (getDolGlobalString('MAIN_MAIL_EMAIL_STARTTLS') ? getDolGlobalString('MAIN_MAIL_EMAIL_STARTTLS') : 0), 1);
569 } else {
570 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
571 }
572 } else {
573 print yn(0).' ('.$langs->trans("NotSupported").')';
574 }
575 print '</td></tr>';
576
577 // SMTP_ALLOW_SELF_SIGNED
578 print '<tr class="oddeven hideonmodemail"><td>'.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").'</td><td>';
579 if (!empty($conf->use_javascript_ajax) || (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer')))) {
580 if (function_exists('openssl_open')) {
581 print $form->selectyesno('MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED', (getDolGlobalString('MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED') ? getDolGlobalString('MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED') : 0), 1);
582 } else {
583 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
584 }
585 } else {
586 print yn(0).' ('.$langs->trans("NotSupported").')';
587 }
588 print '</td></tr>';
589
590 // DKIM
591 print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_ENABLED").'</td><td>';
592 if (!empty($conf->use_javascript_ajax) || (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('swiftmailer')))) {
593 if (function_exists('openssl_open')) {
594 print $form->selectyesno('MAIN_MAIL_EMAIL_DKIM_ENABLED', (getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_ENABLED') ? getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_ENABLED') : 0), 1);
595 } else {
596 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
597 }
598 } else {
599 print yn(0).' ('.$langs->trans("NotSupported").')';
600 }
601 print '</td></tr>';
602
603 // DKIM Domain
604 print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_DOMAIN").'</td>';
605 print '<td><input class="flat" id="MAIN_MAIL_EMAIL_DKIM_DOMAIN" name="MAIN_MAIL_EMAIL_DKIM_DOMAIN" size="32" value="'.getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_DOMAIN');
606 print '"></td></tr>';
607
608 // DKIM Selector
609 print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_SELECTOR").'</td>';
610 print '<td><input class="flat" id="MAIN_MAIL_EMAIL_DKIM_SELECTOR" name="MAIN_MAIL_EMAIL_DKIM_SELECTOR" size="32" value="'.getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_SELECTOR');
611 print '"></td></tr>';
612
613 // DKIM PRIVATE KEY
614 print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").'</td>';
615 print '<td><textarea id="MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY" name="MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY" rows="15" cols="100">'.getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY').'</textarea>';
616 print '</td></tr>';
617
618 print '</table>';
619
620
621 print '<br>';
622
623
624 print '<table class="noborder centpercent">';
625 print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("OtherOptions").'</td><td></td></tr>';
626
627 // Force e-mail recipient
628 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_FORCE_SENDTO").'</td><td>';
629 print '<input class="flat width300" name="MAIN_MAIL_FORCE_SENDTO" value="'.getDolGlobalString('MAIN_MAIL_FORCE_SENDTO').'" />';
630 print '</td></tr>';
631
632 // From
633 $help = $form->textwithpicto('', $langs->trans("EMailHelpMsgSPFDKIM"));
634 print '<tr class="oddeven"><td class="fieldrequired">';
635 print $langs->trans("MAIN_MAIL_EMAIL_FROM", ini_get('sendmail_from') ? ini_get('sendmail_from') : $langs->transnoentities("Undefined"));
636 print ' '.$help;
637 print '</td>';
638 print '<td><input class="flat minwidth300" name="MAIN_MAIL_EMAIL_FROM" value="'.getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
639 print '"></td></tr>';
640
641 // Default from type
642 $liste = array();
643 $liste['user'] = $langs->trans('UserEmail');
644 $liste['company'] = $langs->trans('CompanyEmail').' ('.(!getDolGlobalString('MAIN_INFO_SOCIETE_MAIL') ? $langs->trans("NotDefined") : getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')).')';
645
646 print '<tr class="oddeven"><td>'.$langs->trans('MAIN_MAIL_DEFAULT_FROMTYPE').'</td><td>';
647 print $form->selectarray('MAIN_MAIL_DEFAULT_FROMTYPE', $liste, getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE'), 0);
648 print '</td></tr>';
649
650 // From
651 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ERRORS_TO").'</td>';
652 print '<td><input class="flat width300" name="MAIN_MAIL_ERRORS_TO" value="'.getDolGlobalString('MAIN_MAIL_ERRORS_TO').'">';
653 print '</td></tr>';
654
655 // Autocopy to
656 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
657 print '<td><input class="flat width300" name="MAIN_MAIL_AUTOCOPY_TO" value="'.getDolGlobalString('MAIN_MAIL_AUTOCOPY_TO').'">';
658 print '</td></tr>';
659
660 // Add user to select destinaries list
661 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ENABLED_USER_DEST_SELECT").'</td><td>';
662 print $form->selectyesno('MAIN_MAIL_ENABLED_USER_DEST_SELECT', getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT'), 1);
663 print '</td></tr>';
664 // Disable autoselect to
665 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_NO_WITH_TO_SELECTED").'</td><td>';
666 print $form->selectyesno('MAIN_MAIL_NO_WITH_TO_SELECTED', getDolGlobalString('MAIN_MAIL_NO_WITH_TO_SELECTED'), 1);
667 print '</td></tr>';
668
669 print '</table>';
670
671 print dol_get_fiche_end();
672
673 print $form->buttonsSaveCancel();
674
675 print '</form>';
676} else {
677 print dol_get_fiche_head($head, 'common', '', -1);
678
679 print '<span class="opacitymedium">'.$langs->trans("EMailsDesc")."</span><br>\n";
680 print "<br>\n";
681
682 print $langs->trans("MAIN_DISABLE_ALL_MAILS");
683 if (!empty($conf->use_javascript_ajax)) {
684 print ajax_constantonoff('MAIN_DISABLE_ALL_MAILS', array(), null, 0, 0, 1, 2, 0, 0, '_red').'</a>';
685 } else {
686 print yn(getDolGlobalString('MAIN_DISABLE_ALL_MAILS'));
687 if (getDolGlobalString('MAIN_DISABLE_ALL_MAILS')) {
688 print img_warning($langs->trans("Disabled"));
689 }
690 }
691
692 print "<br>\n";
693 print "<br>\n";
694 print "<br>\n";
695
696
697 if (!getDolGlobalString('MAIN_DISABLE_ALL_MAILS')) {
698 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
699 print '<table class="noborder centpercent">';
700 print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameters").'</td><td></td></tr>';
701
702 // Method
703 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
704 $text = $listofmethods[getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail')];
705 if (empty($text)) {
706 $text = $langs->trans("Undefined").img_warning();
707 }
708 print $text;
709
710 // Note MAIN_HIDE_WARNING_TO_ENCOURAGE_SMTP_SETUP is set to 1 by default if not set
711 if (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail' && getDolGlobalString('MAIN_HIDE_WARNING_TO_ENCOURAGE_SMTP_SETUP')) {
712 $textwarning = $langs->trans("WarningPHPMail", $listofmethods['mail'], $listofmethods['smtps']).'<br>'.$langs->trans("WarningPHPMailA").'<br>'.$langs->trans("WarningPHPMailB").'<br>'.$langs->trans("WarningPHPMailC").'<br><br>'.$langs->trans("WarningPHPMailD");
713 print $form->textwithpicto('', '<span class="small">'.$textwarning.'</span>', 1, 'help', 'nomargintop');
714 }
715
716 print '</td></tr>';
717
718 // Host server
719 if ($linuxlike && (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail')) {
720 //print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike").'</td><td><span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span></td></tr>';
721 } else {
722 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER", ini_get('SMTP') ? ini_get('SMTP') : $langs->transnoentities("Undefined")).'</td><td>'.getDolGlobalString('MAIN_MAIL_SMTP_SERVER').'</td></tr>';
723 }
724
725
726 // Port
727 if ($linuxlike && (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail')) {
728 //print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").'</td><td><span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span></td></tr>';
729 } else {
730 print '<tr class="oddeven"><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').'</td></tr>';
731 }
732
733 // AUTH method
734 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer'))) {
735 $authtype = getDolGlobalString('MAIN_MAIL_SMTPS_AUTH_TYPE', 'LOGIN');
736 $text = '';
737 if ($authtype === "NONE") {
738 $text = $langs->trans("None");
739 } elseif ($authtype === "LOGIN") {
740 $text = $langs->trans("UseAUTHLOGIN");
741 } elseif ($authtype === "PLAIN") {
742 $text = $langs->trans("UseAUTHPLAIN");
743 } elseif ($authtype === "XOAUTH2") {
744 $text = $langs->trans("UseOauth");
745 }
746 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_AUTH_TYPE").'</td><td>'.$text.'</td></tr>';
747 }
748
749 // SMTPS ID
750 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer'))) {
751 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>' . getDolGlobalString('MAIN_MAIL_SMTPS_ID').'</td></tr>';
752 }
753
754 // SMTPS PW
755 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer')) && getDolGlobalString('MAIN_MAIL_SMTPS_AUTH_TYPE') != "XOAUTH2") {
756 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>'.preg_replace('/./', '*', getDolGlobalString('MAIN_MAIL_SMTPS_PW')).'</td></tr>';
757 }
758
759 // SMTPS oauth service
760 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer')) && getDolGlobalString('MAIN_MAIL_SMTPS_AUTH_TYPE') === "XOAUTH2") {
761 $text = $oauthservices[getDolGlobalString('MAIN_MAIL_SMTPS_OAUTH_SERVICE')];
762 if (empty($text)) {
763 $text = $langs->trans("Undefined").img_warning();
764 }
765 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_OAUTH_SERVICE").'</td><td>'.$text.'</td></tr>';
766 }
767
768 // TLS
769 if ($linuxlike && (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail')) {
770 // Nothing
771 } else {
772 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
773 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer'))) {
774 if (function_exists('openssl_open')) {
775 print yn(getDolGlobalString('MAIN_MAIL_EMAIL_TLS'));
776 } else {
777 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
778 }
779 } else {
780 print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
781 }
782 print '</td></tr>';
783 }
784
785 // STARTTLS
786 if ($linuxlike && (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail')) {
787 // Nothing
788 } else {
789 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
790 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer'))) {
791 if (function_exists('openssl_open')) {
792 print yn(getDolGlobalString('MAIN_MAIL_EMAIL_STARTTLS'));
793 } else {
794 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
795 }
796 } else {
797 //print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
798 }
799 print '</td></tr>';
800 }
801
802 // SMTP_ALLOW_SELF_SIGNED
803 if ($linuxlike && (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail')) {
804 // Nothing
805 } else {
806 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").'</td><td>';
807 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer'))) {
808 if (function_exists('openssl_open')) {
809 print yn(getDolGlobalString('MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED'));
810 } else {
811 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
812 }
813 } else {
814 print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
815 }
816 print '</td></tr>';
817 }
818
819 if (getDolGlobalString('MAIN_MAIL_SENDMODE') == 'swiftmailer') {
820 // DKIM
821 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_ENABLED").'</td><td>';
822 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('swiftmailer'))) {
823 if (function_exists('openssl_open')) {
824 print yn(getDolGlobalInt('MAIN_MAIL_EMAIL_DKIM_ENABLED'));
825 } else {
826 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
827 }
828 } else {
829 print yn(0).' ('.$langs->trans("NotSupported").')';
830 }
831 print '</td></tr>';
832
833 // Domain
834 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_DOMAIN").'</td>';
835 print '<td>'.getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_DOMAIN');
836 print '</td></tr>';
837
838 // Selector
839 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_SELECTOR").'</td>';
840 print '<td>'.getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_SELECTOR');
841 print '</td></tr>';
842
843 // PRIVATE KEY
844 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").'</td>';
845 print '<td>'.getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY');
846 print '</td></tr>';
847 }
848
849 print '</table>';
850 print '</div>';
851
852 if (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail' && !getDolGlobalString('MAIN_HIDE_WARNING_TO_ENCOURAGE_SMTP_SETUP')) {
853 $messagetoshow = $langs->trans("WarningPHPMail", $listofmethods['mail'], $listofmethods['smtps']).'<br>'.$langs->trans("WarningPHPMailA").'<br>'.$langs->trans("WarningPHPMailB").'<br>'.$langs->trans("WarningPHPMailC").'<br><br>'.$langs->trans("WarningPHPMailD");
854 $messagetoshow .= ' '.$langs->trans("WarningPHPMailDbis", '{s1}', '{s2}');
855 $linktosetvar1 = '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=disablephpmailwarning&token='.newToken().'">';
856 $linktosetvar2 = '</a>';
857 $messagetoshow = str_replace('{s1}', $linktosetvar1, $messagetoshow);
858 $messagetoshow = str_replace('{s2}', $linktosetvar2, $messagetoshow);
859 //print $messagetoshow;
860 print info_admin($messagetoshow, 0, 0, 'warning', 'nomargintop', '', 'warning');
861 }
862
863 print '<br>';
864 }
865
866 /*
867 if (!getDolGlobalString('MAIN_DISABLE_ALL_MAILS')) {
868 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
869 print '<table class="noborder centpercent">';
870 print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("ParametersForTestEnvironment").'</td><td></td></tr>';
871
872 // Force e-mail recipient
873 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_FORCE_SENDTO").'</td><td>'.getDolGlobalString('MAIN_MAIL_FORCE_SENDTO');
874 if (getDolGlobalString('MAIN_MAIL_FORCE_SENDTO')) {
875 if (!isValidEmail(getDolGlobalString('MAIN_MAIL_FORCE_SENDTO'))) {
876 print img_warning($langs->trans("ErrorBadEMail"));
877 } else {
878 print img_warning($langs->trans("RecipientEmailsWillBeReplacedWithThisValue"));
879 }
880 }
881 print '</td></tr>';
882
883 print '</table>';
884 print '</div>';
885
886 print '<br>';
887 }
888 */
889
890
891 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
892 print '<table class="noborder centpercent">';
893 print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("OtherOptions").'</td><td></td></tr>';
894
895 // Force e-mail recipient
896 if (!getDolGlobalString('MAIN_DISABLE_ALL_MAILS')) {
897 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_FORCE_SENDTO").'</td><td>'.getDolGlobalString('MAIN_MAIL_FORCE_SENDTO');
898 if (getDolGlobalString('MAIN_MAIL_FORCE_SENDTO')) {
899 if (!isValidEmail(getDolGlobalString('MAIN_MAIL_FORCE_SENDTO'))) {
900 print img_warning($langs->trans("ErrorBadEMail"));
901 } else {
902 print img_warning($langs->trans("RecipientEmailsWillBeReplacedWithThisValue"));
903 }
904 }
905 print '</td></tr>';
906 }
907
908 // From
909 $help = $form->textwithpicto('', $langs->trans("EMailHelpMsgSPFDKIM"));
910 print '<tr class="oddeven"><td>';
911 print $langs->trans("MAIN_MAIL_EMAIL_FROM", ini_get('sendmail_from') ? ini_get('sendmail_from') : $langs->transnoentities("Undefined"));
912 print ' '.$help;
913 print '</td>';
914 print '<td>' . getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
915 if (!getDolGlobalString('MAIN_MAIL_EMAIL_FROM')) {
916 print img_warning($langs->trans("Mandatory"));
917 } elseif (!isValidEmail(getDolGlobalString('MAIN_MAIL_EMAIL_FROM'))) {
918 print img_warning($langs->trans("ErrorBadEMail"));
919 }
920 print '</td></tr>';
921
922 // Default from type
923 $liste = array();
924 $liste['user'] = $langs->trans('UserEmail');
925 $liste['company'] = $langs->trans('CompanyEmail').' ('.getDolGlobalString('MAIN_INFO_SOCIETE_MAIL', $langs->trans("NotDefined")).')';
926 $sql = 'SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile';
927 $sql .= ' WHERE active = 1 AND (private = 0 OR private = '.((int) $user->id).')';
928 $resql = $db->query($sql);
929 if ($resql) {
930 $num = $db->num_rows($resql);
931 $i = 0;
932 while ($i < $num) {
933 $obj = $db->fetch_object($resql);
934 if ($obj) {
935 $liste['senderprofile_'.$obj->rowid] = $obj->label.' <'.$obj->email.'>';
936 }
937 $i++;
938 }
939 } else {
940 dol_print_error($db);
941 }
942
943 print '<tr class="oddeven"><td>'.$langs->trans('MAIN_MAIL_DEFAULT_FROMTYPE').'</td>';
944 print '<td>';
945 if (getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE') === 'robot') {
946 print $langs->trans('RobotEmail');
947 } elseif (getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE') === 'user') {
948 print $langs->trans('UserEmail');
949 } elseif (getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE') === 'company') {
950 print $langs->trans('CompanyEmail').' '.dol_escape_htmltag('<'.$mysoc->email.'>');
951 } else {
952 $id = preg_replace('/senderprofile_/', '', getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE'));
953 if ($id > 0) {
954 include_once DOL_DOCUMENT_ROOT.'/core/class/emailsenderprofile.class.php';
955 $emailsenderprofile = new EmailSenderProfile($db);
956 $emailsenderprofile->fetch($id);
957 print $emailsenderprofile->label.' '.dol_escape_htmltag('<'.$emailsenderprofile->email.'>');
958 }
959 }
960 print '</td></tr>';
961
962 // Errors To
963 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ERRORS_TO").'</td>';
964 print '<td>'.(getDolGlobalString('MAIN_MAIL_ERRORS_TO'));
965 if (getDolGlobalString('MAIN_MAIL_ERRORS_TO') && !isValidEmail(getDolGlobalString('MAIN_MAIL_ERRORS_TO'))) {
966 print img_warning($langs->trans("ErrorBadEMail"));
967 }
968 print '</td></tr>';
969
970 // Autocopy to
971 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
972 print '<td>';
973 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_TO')) {
974 $listofemail = explode(',', getDolGlobalString('MAIN_MAIL_AUTOCOPY_TO'));
975 $i = 0;
976 foreach ($listofemail as $key => $val) {
977 if ($i) {
978 print ', ';
979 }
980 $val = trim($val);
981 print $val;
982 if (!isValidEmail($val, 0, 1)) {
983 print img_warning($langs->trans("ErrorBadEMail", $val));
984 }
985 $i++;
986 }
987 } else {
988 print '&nbsp;';
989 }
990 print '</td></tr>';
991
992 //Add user to select destinaries list
993 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ENABLED_USER_DEST_SELECT").'</td><td>'.yn(getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')).'</td></tr>';
994 //Disable autoselect to
995 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_NO_WITH_TO_SELECTED").'</td><td>'.yn(getDolGlobalString('MAIN_MAIL_NO_WITH_TO_SELECTED')).'</td></tr>';
996
997 print '</table>';
998 print '</div>';
999
1000
1001 print dol_get_fiche_end();
1002
1003
1004 // Actions button
1005 print '<div class="tabsAction">';
1006
1007 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
1008
1009 if (!getDolGlobalString('MAIN_DISABLE_ALL_MAILS')) {
1010 if (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') != 'mail' || !$linuxlike) {
1011 if (function_exists('fsockopen') /* && $port && $server */) { // $port and $server can't be empty
1012 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect&token='.newToken().'&date='.dol_now().'#formmailaftertstconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
1013 }
1014 } else {
1015 //print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
1016 }
1017
1018 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&token='.newToken().'&mode=init#formmailbeforetitle">'.$langs->trans("DoTestSend").'</a>';
1019
1020 if (isModEnabled('fckeditor')) {
1021 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testhtml&token='.newToken().'&mode=init#formmailbeforetitle">'.$langs->trans("DoTestSendHTML").'</a>';
1022 }
1023 }
1024
1025 print '</div>';
1026
1027 if (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail' && !getDolGlobalString('MAIN_FIX_FOR_BUGGED_MTA')) {
1028 /*
1029 // Warning 1
1030 if ($linuxlike)
1031 {
1032 $sendmailoption=ini_get('mail.force_extra_parameters');
1033 if (empty($sendmailoption) || ! preg_match('/ba/',$sendmailoption))
1034 {
1035 print info_admin($langs->trans("SendmailOptionNotComplete"));
1036 }
1037 }*/
1038 // Warning 2
1039 print info_admin($langs->trans("SendmailOptionMayHurtBuggedMTA"));
1040 }
1041
1042 if (!in_array($action, array('testconnect', 'test', 'testhtml')) && !getDolGlobalString('MAIN_DISABLE_ALL_MAILS')) {
1043 $text = '';
1044 //if (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail') {
1045 // $text .= $langs->trans("WarningPHPMail", $listofmethods['mail'], $listofmethods['smtps']); // To encourage to use SMTPS
1046 //}
1047
1048 if (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail') {
1049 // mthode php mail
1050 if (getDolGlobalString('MAIN_EXTERNAL_MAIL_SPF_STRING_TO_ADD')) { // Not defined by default. Depend on platform.
1051 // List of string to add in SPF if the setup use the mail method. Example 'include:sendgrid.net include:spf.mydomain.com'
1052 $text .= /* ($text ? '<br><br>' : ''). */$langs->trans("WarningPHPMailSPFDMARC");
1053 } else {
1054 // MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS is list of IPs where email is sent from. Example: '1.2.3.4, [aaaa:bbbb:cccc:dddd]'.
1055 if (getDolGlobalString('MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS')) {
1056 // List of IP shown as record to add in SPF if we use the mail method
1057 $text .= /* ($text ? '<br><br>' : ''). */$langs->trans("WarningPHPMailSPFDMARC");
1058 }
1059 }
1060 } else {
1061 // method smtps or swiftmail
1062 if (getDolGlobalString('MAIN_EXTERNAL_SMTP_SPF_STRING_TO_ADD')) { // Should be required only if you have preset the Dolibarr to use your own SMTP and you want to warn users to update their domain name to match your SMTP server.
1063 // List of string to add in SPF if we use the smtp method. Example 'include:spf.mydomain.com'
1064 $text .= /* ($text ? '<br><br>' : ''). */$langs->trans("WarningPHPMailSPF", getDolGlobalString('MAIN_EXTERNAL_SMTP_SPF_STRING_TO_ADD'));
1065 }
1066 if (getDolGlobalString('MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS')) { // Not defined by default. Depend on platform.
1067 $ipstoshow = '';
1068 // List of IP shown as record to add as allowed IP if we use the smtp method. Value is '1.2.3.4, [aaaa:bbbb:cccc:dddd]'
1069 $arrayipstoshow = explode(',', getDolGlobalString('MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS'));
1070 foreach ($arrayipstoshow as $iptoshow) {
1071 // If MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS is an URL to get/show the public IP/name of server detected dynamically
1072 if (preg_match('/^http/i', $iptoshow)) {
1073 $tmpresult = getURLContent($iptoshow, 'GET', '', 1, array(), array('http', 'https'), 0);
1074 if (!empty($tmpresult['content'])) {
1075 $iptoshow = $tmpresult['content'];
1076 } else {
1077 $iptoshow = ''; // Failed to get IP
1078 }
1079 }
1080 $ipstoshow .= ($ipstoshow ? ', ' : '').trim($iptoshow);
1081 }
1082 if ($ipstoshow) {
1083 $text .= ($text ? '<br><br>' : '').$langs->trans("WarningPHPMail2", $ipstoshow);
1084 }
1085 }
1086 }
1087
1088 // Build list of main email addresses in $emailstotest and their domain to test in $domainstotest
1089 $emailstotest = array();
1090 if (getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')) {
1091 $emailstotest[getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')] = getDomainFromURL(preg_replace('/^.*@/', '', getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')), 1);
1092 }
1093 if (getDolGlobalString('MAIN_MAIL_EMAIL_FROM')) {
1094 $emailstotest[getDolGlobalString('MAIN_MAIL_EMAIL_FROM')] = getDomainFromURL(preg_replace('/^.*@/', '', getDolGlobalString('MAIN_MAIL_EMAIL_FROM')), 1);
1095 }
1096 if (!empty($user->email)) {
1097 $emailstotest[$user->email] = getDomainFromURL(preg_replace('/^.*@/', '', $user->email), 1);
1098 }
1099 $domainstotest = array();
1100 foreach ($emailstotest as $email => $domain) {
1101 if (empty($domainstotest[$domain])) {
1102 $domainstotest[$domain] = array($email => $email);
1103 } else {
1104 $domainstotest[$domain][$email] = $email;
1105 }
1106 }
1107
1108 // Test DNS entry for emails
1109 foreach (array('SPF', 'DMARC') as $dnstype) {
1110 foreach ($domainstotest as $domaintotest => $listofemails) {
1111 $dnsinfo = false;
1112 $foundforemail = 0;
1113 if (!empty($domaintotest) && function_exists('dns_get_record') && !getDolGlobalString('MAIN_DISABLE_DNS_GET_RECORD')) {
1114 $domain = $domaintotest;
1115 if ($dnstype == 'DMARC') {
1116 $domain = '_dmarc.'.$domain;
1117 }
1118 $dnsinfo = dns_get_record($domain, DNS_TXT);
1119 }
1120 if (!empty($dnsinfo) && is_array($dnsinfo)) {
1121 foreach ($dnsinfo as $info) {
1122 if (($dnstype == 'SPF' && stripos($info['txt'], 'v=spf') !== false)
1123 || ($dnstype == 'DMARC' && stripos($info['txt'], 'v=dmarc') !== false)) {
1124 $foundforemail++;
1125 $text .= ($text ? '<br>' : '').'- '.$langs->trans("ActualMailDNSRecordFound", '<b>'.$dnstype.'</b>', '<b>'.implode(', ', $listofemails).'</b>', '<span class="opacitylow">'.$info['txt'].'</span>');
1126 }
1127 }
1128 }
1129 if (!$foundforemail) {
1130 $text .= ($text ? '<br>' : '').'- '.$langs->trans("ActualMailDNSRecordFound", '<b>'.$dnstype.'</b>', '<b>'.implode(', ', $listofemails).'</b>', '<span class="opacitymedium">'.$langs->transnoentitiesnoconv("None").'</span>');
1131 }
1132 }
1133 }
1134
1135 if ($text) {
1136 print info_admin($langs->trans("SPFAndDMARCInformation").' :<br>'.$text, 0, 0, '1', '');
1137 }
1138 }
1139
1140 // Run the test to connect
1141 if ($action == 'testconnect') {
1142 print '<div id="formmailaftertstconnect" name="formmailaftertstconnect"></div>';
1143 print load_fiche_titre($langs->trans("DoTestServerAvailability"));
1144
1145 include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
1146 $mail = new CMailFile('', '', '', '', array(), array(), array(), '', '', 0, 0, '', '', '', $trackid, $sendcontext);
1147 $result = $mail->check_server_port($server, $port);
1148 if ($result) {
1149 print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort", $server, $port).'</div>';
1150 } else {
1151 $errormsg = $langs->trans("ServerNotAvailableOnIPOrPort", $server, $port);
1152
1153 if ($mail->error) {
1154 $errormsg .= ' - '.$mail->error;
1155 }
1156
1157 setEventMessages($errormsg, null, 'errors');
1158 }
1159 print '<br>';
1160 }
1161
1162 // Show email send test form
1163 if ($action == 'test' || $action == 'testhtml') {
1164 print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
1165 print load_fiche_titre($action == 'testhtml' ? $langs->trans("DoTestSendHTML") : $langs->trans("DoTestSend"));
1166
1167 print dol_get_fiche_head(array(), '', '', -1);
1168
1169 // Create form object
1170 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1171 $formmail = new FormMail($db);
1172 $formmail->trackid = (($action == 'testhtml') ? "testhtml" : "test");
1173 $formmail->fromname = (GETPOSTISSET('fromname') ? GETPOST('fromname') : getDolGlobalString('MAIN_MAIL_EMAIL_FROM'));
1174 $formmail->frommail = (GETPOSTISSET('frommail') ? GETPOST('frommail') : getDolGlobalString('MAIN_MAIL_EMAIL_FROM'));
1175 $formmail->fromid = $user->id;
1176 $formmail->fromalsorobot = 1;
1177 $formmail->fromtype = (GETPOSTISSET('fromtype') ? GETPOST('fromtype', 'aZ09') : getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE', 'user'));
1178 $formmail->withfromreadonly = 1;
1179 $formmail->withsubstit = 1;
1180 $formmail->withfrom = 1;
1181 $formmail->witherrorsto = 1;
1182 $formmail->withto = (GETPOSTISSET('sendto') ? GETPOST('sendto', 'restricthtml') : ($user->email ? $user->email : 1));
1183 $formmail->withtocc = (GETPOSTISSET('sendtocc') ? GETPOST('sendtocc', 'restricthtml') : 1); // ! empty to keep field if empty
1184 $formmail->withtoccc = (GETPOSTISSET('sendtoccc') ? GETPOST('sendtoccc', 'restricthtml') : 1); // ! empty to keep field if empty
1185 $formmail->withtopic = (GETPOSTISSET('subject') ? GETPOST('subject') : $langs->trans("Test"));
1186 $formmail->withtopicreadonly = 0;
1187 $formmail->withfile = 2;
1188
1189 $formmail->withlayout = 'emailing'; // Note: MAIN_EMAIL_USE_LAYOUT must be set
1190 $formmail->withaiprompt = ($action == 'testhtml' ? 'html' : 'text'); // Note: Module AI must be enabled
1191
1192 $formmail->withbody = (GETPOSTISSET('message') ? GETPOST('message', 'restricthtml') : ($action == 'testhtml' ? $langs->transnoentities("PredefinedMailTestHtml") : $langs->transnoentities("PredefinedMailTest")));
1193 $formmail->withbodyreadonly = 0;
1194 $formmail->withcancel = 1;
1195 $formmail->withdeliveryreceipt = 1;
1196 $formmail->withfckeditor = ($action == 'testhtml' ? 1 : 0);
1197 $formmail->ckeditortoolbar = 'dolibarr_mailings';
1198 // Array of substitutions
1199 $formmail->substit = $substitutionarrayfortest;
1200 // Array of complementary POST parameters
1201 $formmail->param["action"] = "send";
1202 $formmail->param["models"] = "body";
1203 $formmail->param["mailid"] = 0;
1204 $formmail->param["returnurl"] = $_SERVER["PHP_SELF"];
1205
1206 // Init list of files
1207 if (GETPOST("mode", "aZ09") == 'init') {
1208 $formmail->clear_attached_files();
1209 }
1210
1211 print $formmail->get_form('addfile', 'removefile');
1212
1213 print dol_get_fiche_end();
1214
1215 // References
1216 if (!empty($user->admin)) {
1217 print '<br><br>';
1218 print '<span class="opacitymedium">'.$langs->trans("EMailsWillHaveMessageID").': ';
1219 print dol_escape_htmltag('<timestamp.*@'.dol_getprefix('email').'>');
1220 print '</span>';
1221 }
1222 }
1223}
1224
1225// End of page
1226llxFooter();
1227$db->close();
$id
Definition account.php:48
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:87
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:71
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class for EmailSenderProfile.
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...
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.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
dol_now($mode='auto')
Return date for now.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
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_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
getDomainFromURL($url, $mode=0)
Function get second level domain name.
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1)
Function to get a content from an URL (use proxy if proxy defined).
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
dol_hash($chain, $type='0', $nosalt=0, $mode=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.