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