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