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