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