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