dolibarr 21.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 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024 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', 'aZ09');
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 '<table class="noborder centpercent">';
386 print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameters").'</td><td></td></tr>';
387
388 // Method
389 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
390
391 // SuperAdministrator access only
392 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
393 print $form->selectarray('MAIN_MAIL_SENDMODE', $listofmethods, getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'));
394 } else {
395 $text = $listofmethods[getDolGlobalString('MAIN_MAIL_SENDMODE')];
396 if (empty($text)) {
397 $text = $langs->trans("Undefined");
398 }
399 $htmltext = $langs->trans("ContactSuperAdminForChange");
400 print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
401 print '<input type="hidden" name="MAIN_MAIL_SENDMODE" value="'.getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail').'">';
402 }
403 print '</td></tr>';
404
405 // Host server
406 print '<tr class="oddeven hideonmodemail">';
407 if (!$conf->use_javascript_ajax && $linuxlike && getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail') {
408 print '<td>';
409 print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
410 print '</td><td>';
411 print '<span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
412 print '</td>';
413 } else {
414 print '<td>';
415 $mainserver = getDolGlobalString('MAIN_MAIL_SMTP_SERVER');
416 $smtpserver = ini_get('SMTP') ? ini_get('SMTP') : $langs->transnoentities("Undefined");
417 if ($linuxlike) {
418 print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
419 } else {
420 print $langs->trans("MAIN_MAIL_SMTP_SERVER", $smtpserver);
421 }
422 print '</td><td>';
423 // SuperAdministrator access only
424 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
425 print '<input class="flat minwidth300" id="MAIN_MAIL_SMTP_SERVER" name="MAIN_MAIL_SMTP_SERVER" value="'.$mainserver.'" autocomplete="off">';
426 print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_sav" name="MAIN_MAIL_SMTP_SERVER_sav" value="'.$mainserver.'">';
427 print '<span id="smtp_server_mess" class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
428 print ' <span class="opacitymedium smtp_method">'.$langs->trans("SeeLinkToOnlineDocumentation").'</span>';
429 } else {
430 $text = !empty($mainserver) ? $mainserver : $smtpserver;
431 $htmltext = $langs->trans("ContactSuperAdminForChange");
432 print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
433 print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER" name="MAIN_MAIL_SMTP_SERVER" value="'.$mainserver.'">';
434 }
435 print '</td>';
436 }
437 print '</tr>';
438
439 // Port
440 print '<tr class="oddeven hideonmodemail"><td>';
441 if (!$conf->use_javascript_ajax && $linuxlike && getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail') {
442 print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
443 print '</td><td>';
444 print '<span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
445 } else {
446 $mainport = getDolGlobalString('MAIN_MAIL_SMTP_PORT');
447 $smtpport = ini_get('smtp_port') ? ini_get('smtp_port') : $langs->transnoentities("Undefined");
448 if ($linuxlike) {
449 print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
450 } else {
451 print $langs->trans("MAIN_MAIL_SMTP_PORT", $smtpport);
452 }
453 print '</td><td>';
454 // SuperAdministrator access only
455 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
456 print '<input class="flat" id="MAIN_MAIL_SMTP_PORT" name="MAIN_MAIL_SMTP_PORT" size="3" value="'.$mainport.'">';
457 print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_sav" name="MAIN_MAIL_SMTP_PORT_sav" value="'.$mainport.'">';
458 print '<span id="smtp_port_mess" class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
459 } else {
460 $text = (!empty($mainport) ? $mainport : $smtpport);
461 $htmltext = $langs->trans("ContactSuperAdminForChange");
462 print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
463 print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT" name="MAIN_MAIL_SMTP_PORT" value="'.$mainport.'">';
464 }
465 }
466 print '</td></tr>';
467
468 // Auth mode
469 if (!empty($conf->use_javascript_ajax) || (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer')))) {
470 print '<tr class="oddeven smtp_auth_method"><td>'.$langs->trans("MAIN_MAIL_SMTPS_AUTH_TYPE").'</td><td>';
471 $vartosmtpstype = 'MAIN_MAIL_SMTPS_AUTH_TYPE';
472 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
473 // 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)
474 print '<input type="radio" id="radio_pw" name="'.$vartosmtpstype.'" value="LOGIN"'.(getDolGlobalString($vartosmtpstype, 'LOGIN') == 'LOGIN' ? ' checked' : '').'> ';
475 print '<label for="radio_pw" >'.$langs->trans("UseAUTHLOGIN").'</label>';
476 print '<br>';
477 print '<input type="radio" id="radio_plain" name="'.$vartosmtpstype.'" value="PLAIN"'.(getDolGlobalString($vartosmtpstype, 'PLAIN') == 'PLAIN' ? ' checked' : '').'> ';
478 print '<label for="radio_plain" >'.$langs->trans("UseAUTHPLAIN").'</label>';
479 print '<br>';
480 print '<input type="radio" id="radio_oauth" name="'.$vartosmtpstype.'" value="XOAUTH2"'.(getDolGlobalString($vartosmtpstype) == 'XOAUTH2' ? ' checked' : '').(isModEnabled('oauth') ? '' : ' disabled').'> ';
481 print '<label for="radio_oauth" >'.$form->textwithpicto($langs->trans("UseOauth"), $langs->trans("OauthNotAvailableForAllAndHadToBeCreatedBefore")).'</label>';
482 if (!isModEnabled('oauth')) {
483 print ' &nbsp; <a href="'.DOL_URL_ROOT.'/admin/modules.php?search_keyword=oauth">'.$langs->trans("EnableModuleX", "OAuth").'</a>';
484 } else {
485 print ' &nbsp; <a href="'.DOL_URL_ROOT.'/admin/oauth.php">'.$langs->trans("SetupModuleX", " OAuth").'</a>';
486 }
487 } else {
488 $value = getDolGlobalString($vartosmtpstype, 'LOGIN');
489 $htmltext = $langs->trans("ContactSuperAdminForChange");
490 print $form->textwithpicto($langs->trans("MAIN_MAIL_SMTPS_AUTH_TYPE"), $htmltext, 1, 'superadmin');
491 print '<input type="hidden" id="MAIN_MAIL_SMTPS_AUTH_TYPE" name="MAIN_MAIL_SMTPS_AUTH_TYPE" value="'.$value.'">';
492 }
493 print '</td></tr>';
494 }
495
496 // ID
497 if (!empty($conf->use_javascript_ajax) || (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer')))) {
498 $mainstmpid = getDolGlobalString('MAIN_MAIL_SMTPS_ID');
499 print '<tr class="drag drop oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>';
500 // SuperAdministrator access only
501 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
502 print '<input class="flat" name="MAIN_MAIL_SMTPS_ID" size="32" value="'.$mainstmpid.'">';
503 } else {
504 $htmltext = $langs->trans("ContactSuperAdminForChange");
505 print $form->textwithpicto(getDolGlobalString('MAIN_MAIL_SMTPS_ID'), $htmltext, 1, 'superadmin');
506 print '<input type="hidden" name="MAIN_MAIL_SMTPS_ID" value="'.$mainstmpid.'">';
507 }
508 print '</td></tr>';
509 }
510
511
512 // PW
513 if (!empty($conf->use_javascript_ajax) || (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer')))) {
514 $mainsmtppw = getDolGlobalString('MAIN_MAIL_SMTPS_PW');
515 print '<tr class="drag drop oddeven smtp_pw"><td>';
516 print $form->textwithpicto($langs->trans("MAIN_MAIL_SMTPS_PW"), $langs->trans("WithGMailYouCanCreateADedicatedPassword"));
517 print '</td><td>';
518 // SuperAdministrator access only
519 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
520 print '<input class="flat" type="password" name="MAIN_MAIL_SMTPS_PW" size="32" value="' . htmlspecialchars($mainsmtppw, ENT_COMPAT, 'UTF-8') . '" autocomplete="off">';
521 } else {
522 $htmltext = $langs->trans("ContactSuperAdminForChange");
523 print $form->textwithpicto(getDolGlobalString('MAIN_MAIL_SMTPS_PW'), $htmltext, 1, 'superadmin');
524 print '<input type="hidden" name="MAIN_MAIL_SMTPS_PW" value="' . htmlspecialchars($mainsmtppw, ENT_COMPAT, 'UTF-8') . '">';
525 }
526 print '</td></tr>';
527 }
528
529 // OAUTH service provider
530 if (!empty($conf->use_javascript_ajax) || (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer')))) {
531 print '<tr class="oddeven smtp_oauth_service"><td>'.$langs->trans("MAIN_MAIL_SMTPS_OAUTH_SERVICE").'</td><td>';
532
533 // SuperAdministrator access only
534 if (!isModEnabled('multicompany') || ($user->admin && !$user->entity)) {
535 print $form->selectarray('MAIN_MAIL_SMTPS_OAUTH_SERVICE', $oauthservices, getDolGlobalString('MAIN_MAIL_SMTPS_OAUTH_SERVICE'));
536 } else {
537 $text = $oauthservices[getDolGlobalString('MAIN_MAIL_SMTPS_OAUTH_SERVICE')];
538 if (empty($text)) {
539 $text = $langs->trans("Undefined");
540 }
541 $htmltext = $langs->trans("ContactSuperAdminForChange");
542 print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
543 print '<input type="hidden" name="MAIN_MAIL_SMTPS_OAUTH_SERVICE" value="' . getDolGlobalString('MAIN_MAIL_SMTPS_OAUTH_SERVICE').'">';
544 }
545 print '</td></tr>';
546 }
547
548 // TLS
549 print '<tr class="oddeven hideonmodemail"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
550 if (!empty($conf->use_javascript_ajax) || (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer')))) {
551 if (function_exists('openssl_open')) {
552 print $form->selectyesno('MAIN_MAIL_EMAIL_TLS', (getDolGlobalString('MAIN_MAIL_EMAIL_TLS') ? getDolGlobalString('MAIN_MAIL_EMAIL_TLS') : 0), 1);
553 } else {
554 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
555 }
556 } else {
557 print yn(0).' ('.$langs->trans("NotSupported").')';
558 }
559 print '</td></tr>';
560
561 // STARTTLS
562 print '<tr class="oddeven hideonmodemail"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
563 if (!empty($conf->use_javascript_ajax) || (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer')))) {
564 if (function_exists('openssl_open')) {
565 print $form->selectyesno('MAIN_MAIL_EMAIL_STARTTLS', (getDolGlobalString('MAIN_MAIL_EMAIL_STARTTLS') ? getDolGlobalString('MAIN_MAIL_EMAIL_STARTTLS') : 0), 1);
566 } else {
567 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
568 }
569 } else {
570 print yn(0).' ('.$langs->trans("NotSupported").')';
571 }
572 print '</td></tr>';
573
574 // SMTP_ALLOW_SELF_SIGNED
575 print '<tr class="oddeven hideonmodemail"><td>'.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").'</td><td>';
576 if (!empty($conf->use_javascript_ajax) || (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer')))) {
577 if (function_exists('openssl_open')) {
578 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);
579 } else {
580 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
581 }
582 } else {
583 print yn(0).' ('.$langs->trans("NotSupported").')';
584 }
585 print '</td></tr>';
586
587 // DKIM
588 print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_ENABLED").'</td><td>';
589 if (!empty($conf->use_javascript_ajax) || (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('swiftmailer')))) {
590 if (function_exists('openssl_open')) {
591 print $form->selectyesno('MAIN_MAIL_EMAIL_DKIM_ENABLED', (getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_ENABLED') ? getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_ENABLED') : 0), 1);
592 } else {
593 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
594 }
595 } else {
596 print yn(0).' ('.$langs->trans("NotSupported").')';
597 }
598 print '</td></tr>';
599
600 // DKIM Domain
601 print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_DOMAIN").'</td>';
602 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');
603 print '"></td></tr>';
604
605 // DKIM Selector
606 print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_SELECTOR").'</td>';
607 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');
608 print '"></td></tr>';
609
610 // DKIM PRIVATE KEY
611 print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").'</td>';
612 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>';
613 print '</td></tr>';
614
615 print '</table>';
616
617
618 print '<br>';
619
620
621 print '<table class="noborder centpercent">';
622 print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("OtherOptions").'</td><td></td></tr>';
623
624 // Force e-mail recipient
625 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_FORCE_SENDTO").'</td><td>';
626 print '<input class="flat width300" name="MAIN_MAIL_FORCE_SENDTO" value="'.getDolGlobalString('MAIN_MAIL_FORCE_SENDTO').'" />';
627 print '</td></tr>';
628
629 // From
630 $help = $form->textwithpicto('', $langs->trans("EMailHelpMsgSPFDKIM"));
631 print '<tr class="oddeven"><td class="fieldrequired">';
632 print $langs->trans("MAIN_MAIL_EMAIL_FROM", ini_get('sendmail_from') ? ini_get('sendmail_from') : $langs->transnoentities("Undefined"));
633 print ' '.$help;
634 print '</td>';
635 print '<td><input class="flat minwidth300" name="MAIN_MAIL_EMAIL_FROM" value="'.getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
636 print '"></td></tr>';
637
638 // Default from type
639 $liste = array();
640 $liste['user'] = $langs->trans('UserEmail');
641 $liste['company'] = $langs->trans('CompanyEmail').' ('.(!getDolGlobalString('MAIN_INFO_SOCIETE_MAIL') ? $langs->trans("NotDefined") : getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')).')';
642
643 print '<tr class="oddeven"><td>'.$langs->trans('MAIN_MAIL_DEFAULT_FROMTYPE').'</td><td>';
644 print $form->selectarray('MAIN_MAIL_DEFAULT_FROMTYPE', $liste, getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE'), 0);
645 print '</td></tr>';
646
647 // From
648 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ERRORS_TO").'</td>';
649 print '<td><input class="flat width300" name="MAIN_MAIL_ERRORS_TO" value="'.getDolGlobalString('MAIN_MAIL_ERRORS_TO').'">';
650 print '</td></tr>';
651
652 // Autocopy to
653 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
654 print '<td><input class="flat width300" name="MAIN_MAIL_AUTOCOPY_TO" value="'.getDolGlobalString('MAIN_MAIL_AUTOCOPY_TO').'">';
655 print '</td></tr>';
656
657 // Add user to select destinaries list
658 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ENABLED_USER_DEST_SELECT").'</td><td>';
659 print $form->selectyesno('MAIN_MAIL_ENABLED_USER_DEST_SELECT', getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT'), 1);
660 print '</td></tr>';
661 // Disable autoselect to
662 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_NO_WITH_TO_SELECTED").'</td><td>';
663 print $form->selectyesno('MAIN_MAIL_NO_WITH_TO_SELECTED', getDolGlobalString('MAIN_MAIL_NO_WITH_TO_SELECTED'), 1);
664 print '</td></tr>';
665
666 print '</table>';
667
668 print dol_get_fiche_end();
669
670 print $form->buttonsSaveCancel();
671
672 print '</form>';
673} else {
674 print dol_get_fiche_head($head, 'common', '', -1);
675
676 print '<span class="opacitymedium">'.$langs->trans("EMailsDesc")."</span><br>\n";
677 print "<br>\n";
678
679 print $langs->trans("MAIN_DISABLE_ALL_MAILS");
680 if (!empty($conf->use_javascript_ajax)) {
681 print ajax_constantonoff('MAIN_DISABLE_ALL_MAILS', array(), null, 0, 0, 1, 2, 0, 0, '_red').'</a>';
682 } else {
683 print yn(getDolGlobalString('MAIN_DISABLE_ALL_MAILS'));
684 if (getDolGlobalString('MAIN_DISABLE_ALL_MAILS')) {
685 print img_warning($langs->trans("Disabled"));
686 }
687 }
688
689 print "<br>\n";
690 print "<br>\n";
691 print "<br>\n";
692
693
694 if (!getDolGlobalString('MAIN_DISABLE_ALL_MAILS')) {
695 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
696 print '<table class="noborder centpercent">';
697 print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameters").'</td><td></td></tr>';
698
699 // Method
700 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
701 $text = $listofmethods[getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail')];
702 if (empty($text)) {
703 $text = $langs->trans("Undefined").img_warning();
704 }
705 print $text;
706
707 // Note MAIN_HIDE_WARNING_TO_ENCOURAGE_SMTP_SETUP is set to 1 by default if not set
708 if (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail' && getDolGlobalString('MAIN_HIDE_WARNING_TO_ENCOURAGE_SMTP_SETUP')) {
709 $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");
710 print $form->textwithpicto('', '<span class="small">'.$textwarning.'</span>', 1, 'help', 'nomargintop');
711 }
712
713 print '</td></tr>';
714
715 // Host server
716 if ($linuxlike && (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail')) {
717 //print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike").'</td><td><span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span></td></tr>';
718 } else {
719 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>';
720 }
721
722
723 // Port
724 if ($linuxlike && (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail')) {
725 //print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").'</td><td><span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span></td></tr>';
726 } else {
727 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>';
728 }
729
730 // AUTH method
731 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer'))) {
732 $authtype = getDolGlobalString('MAIN_MAIL_SMTPS_AUTH_TYPE', 'LOGIN');
733 $text = '';
734 if ($authtype === "LOGIN") {
735 $text = $langs->trans("UseAUTHLOGIN");
736 } elseif ($authtype === "PLAIN") {
737 $text = $langs->trans("UseAUTHPLAIN");
738 } elseif ($authtype === "XOAUTH2") {
739 $text = $langs->trans("UseOauth");
740 }
741 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_AUTH_TYPE").'</td><td>'.$text.'</td></tr>';
742 }
743
744 // SMTPS ID
745 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer'))) {
746 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>' . getDolGlobalString('MAIN_MAIL_SMTPS_ID').'</td></tr>';
747 }
748
749 // SMTPS PW
750 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer')) && getDolGlobalString('MAIN_MAIL_SMTPS_AUTH_TYPE') != "XOAUTH2") {
751 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>'.preg_replace('/./', '*', getDolGlobalString('MAIN_MAIL_SMTPS_PW')).'</td></tr>';
752 }
753
754 // SMTPS oauth service
755 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer')) && getDolGlobalString('MAIN_MAIL_SMTPS_AUTH_TYPE') === "XOAUTH2") {
756 $text = $oauthservices[getDolGlobalString('MAIN_MAIL_SMTPS_OAUTH_SERVICE')];
757 if (empty($text)) {
758 $text = $langs->trans("Undefined").img_warning();
759 }
760 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_OAUTH_SERVICE").'</td><td>'.$text.'</td></tr>';
761 }
762
763 // TLS
764 if ($linuxlike && (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail')) {
765 // Nothing
766 } else {
767 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
768 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer'))) {
769 if (function_exists('openssl_open')) {
770 print yn(getDolGlobalString('MAIN_MAIL_EMAIL_TLS'));
771 } else {
772 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
773 }
774 } else {
775 print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
776 }
777 print '</td></tr>';
778 }
779
780 // STARTTLS
781 if ($linuxlike && (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail')) {
782 // Nothing
783 } else {
784 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
785 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer'))) {
786 if (function_exists('openssl_open')) {
787 print yn(getDolGlobalString('MAIN_MAIL_EMAIL_STARTTLS'));
788 } else {
789 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
790 }
791 } else {
792 //print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
793 }
794 print '</td></tr>';
795 }
796
797 // SMTP_ALLOW_SELF_SIGNED
798 if ($linuxlike && (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail')) {
799 // Nothing
800 } else {
801 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").'</td><td>';
802 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('smtps', 'swiftmailer'))) {
803 if (function_exists('openssl_open')) {
804 print yn(getDolGlobalString('MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED'));
805 } else {
806 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
807 }
808 } else {
809 print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
810 }
811 print '</td></tr>';
812 }
813
814 if (getDolGlobalString('MAIN_MAIL_SENDMODE') == 'swiftmailer') {
815 // DKIM
816 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_ENABLED").'</td><td>';
817 if (in_array(getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail'), array('swiftmailer'))) {
818 if (function_exists('openssl_open')) {
819 print yn(getDolGlobalInt('MAIN_MAIL_EMAIL_DKIM_ENABLED'));
820 } else {
821 print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
822 }
823 } else {
824 print yn(0).' ('.$langs->trans("NotSupported").')';
825 }
826 print '</td></tr>';
827
828 // Domain
829 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_DOMAIN").'</td>';
830 print '<td>'.getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_DOMAIN');
831 print '</td></tr>';
832
833 // Selector
834 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_SELECTOR").'</td>';
835 print '<td>'.getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_SELECTOR');
836 print '</td></tr>';
837
838 // PRIVATE KEY
839 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").'</td>';
840 print '<td>'.getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY');
841 print '</td></tr>';
842 }
843
844 print '</table>';
845 print '</div>';
846
847 if (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail' && !getDolGlobalString('MAIN_HIDE_WARNING_TO_ENCOURAGE_SMTP_SETUP')) {
848 $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");
849 $messagetoshow .= ' '.$langs->trans("WarningPHPMailDbis", '{s1}', '{s2}');
850 $linktosetvar1 = '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=disablephpmailwarning&token='.newToken().'">';
851 $linktosetvar2 = '</a>';
852 $messagetoshow = str_replace('{s1}', $linktosetvar1, $messagetoshow);
853 $messagetoshow = str_replace('{s2}', $linktosetvar2, $messagetoshow);
854 //print $messagetoshow;
855 print info_admin($messagetoshow, 0, 0, 'warning', 'nomargintop', '', 'warning');
856 }
857
858 print '<br>';
859 }
860
861 /*
862 if (!getDolGlobalString('MAIN_DISABLE_ALL_MAILS')) {
863 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
864 print '<table class="noborder centpercent">';
865 print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("ParametersForTestEnvironment").'</td><td></td></tr>';
866
867 // Force e-mail recipient
868 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_FORCE_SENDTO").'</td><td>'.getDolGlobalString('MAIN_MAIL_FORCE_SENDTO');
869 if (getDolGlobalString('MAIN_MAIL_FORCE_SENDTO')) {
870 if (!isValidEmail(getDolGlobalString('MAIN_MAIL_FORCE_SENDTO'))) {
871 print img_warning($langs->trans("ErrorBadEMail"));
872 } else {
873 print img_warning($langs->trans("RecipientEmailsWillBeReplacedWithThisValue"));
874 }
875 }
876 print '</td></tr>';
877
878 print '</table>';
879 print '</div>';
880
881 print '<br>';
882 }
883 */
884
885
886 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
887 print '<table class="noborder centpercent">';
888 print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("OtherOptions").'</td><td></td></tr>';
889
890 // Force e-mail recipient
891 if (!getDolGlobalString('MAIN_DISABLE_ALL_MAILS')) {
892 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_FORCE_SENDTO").'</td><td>'.getDolGlobalString('MAIN_MAIL_FORCE_SENDTO');
893 if (getDolGlobalString('MAIN_MAIL_FORCE_SENDTO')) {
894 if (!isValidEmail(getDolGlobalString('MAIN_MAIL_FORCE_SENDTO'))) {
895 print img_warning($langs->trans("ErrorBadEMail"));
896 } else {
897 print img_warning($langs->trans("RecipientEmailsWillBeReplacedWithThisValue"));
898 }
899 }
900 print '</td></tr>';
901 }
902
903 // From
904 $help = $form->textwithpicto('', $langs->trans("EMailHelpMsgSPFDKIM"));
905 print '<tr class="oddeven"><td>';
906 print $langs->trans("MAIN_MAIL_EMAIL_FROM", ini_get('sendmail_from') ? ini_get('sendmail_from') : $langs->transnoentities("Undefined"));
907 print ' '.$help;
908 print '</td>';
909 print '<td>' . getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
910 if (!getDolGlobalString('MAIN_MAIL_EMAIL_FROM')) {
911 print img_warning($langs->trans("Mandatory"));
912 } elseif (!isValidEmail(getDolGlobalString('MAIN_MAIL_EMAIL_FROM'))) {
913 print img_warning($langs->trans("ErrorBadEMail"));
914 }
915 print '</td></tr>';
916
917 // Default from type
918 $liste = array();
919 $liste['user'] = $langs->trans('UserEmail');
920 $liste['company'] = $langs->trans('CompanyEmail').' ('.getDolGlobalString('MAIN_INFO_SOCIETE_MAIL', $langs->trans("NotDefined")).')';
921 $sql = 'SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile';
922 $sql .= ' WHERE active = 1 AND (private = 0 OR private = '.((int) $user->id).')';
923 $resql = $db->query($sql);
924 if ($resql) {
925 $num = $db->num_rows($resql);
926 $i = 0;
927 while ($i < $num) {
928 $obj = $db->fetch_object($resql);
929 if ($obj) {
930 $liste['senderprofile_'.$obj->rowid] = $obj->label.' <'.$obj->email.'>';
931 }
932 $i++;
933 }
934 } else {
935 dol_print_error($db);
936 }
937
938 print '<tr class="oddeven"><td>'.$langs->trans('MAIN_MAIL_DEFAULT_FROMTYPE').'</td>';
939 print '<td>';
940 if (getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE') === 'robot') {
941 print $langs->trans('RobotEmail');
942 } elseif (getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE') === 'user') {
943 print $langs->trans('UserEmail');
944 } elseif (getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE') === 'company') {
945 print $langs->trans('CompanyEmail').' '.dol_escape_htmltag('<'.$mysoc->email.'>');
946 } else {
947 $id = preg_replace('/senderprofile_/', '', getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE'));
948 if ($id > 0) {
949 include_once DOL_DOCUMENT_ROOT.'/core/class/emailsenderprofile.class.php';
950 $emailsenderprofile = new EmailSenderProfile($db);
951 $emailsenderprofile->fetch($id);
952 print $emailsenderprofile->label.' '.dol_escape_htmltag('<'.$emailsenderprofile->email.'>');
953 }
954 }
955 print '</td></tr>';
956
957 // Errors To
958 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ERRORS_TO").'</td>';
959 print '<td>'.(getDolGlobalString('MAIN_MAIL_ERRORS_TO'));
960 if (getDolGlobalString('MAIN_MAIL_ERRORS_TO') && !isValidEmail(getDolGlobalString('MAIN_MAIL_ERRORS_TO'))) {
961 print img_warning($langs->trans("ErrorBadEMail"));
962 }
963 print '</td></tr>';
964
965 // Autocopy to
966 print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
967 print '<td>';
968 if (getDolGlobalString('MAIN_MAIL_AUTOCOPY_TO')) {
969 $listofemail = explode(',', getDolGlobalString('MAIN_MAIL_AUTOCOPY_TO'));
970 $i = 0;
971 foreach ($listofemail as $key => $val) {
972 if ($i) {
973 print ', ';
974 }
975 $val = trim($val);
976 print $val;
977 if (!isValidEmail($val, 0, 1)) {
978 print img_warning($langs->trans("ErrorBadEMail", $val));
979 }
980 $i++;
981 }
982 } else {
983 print '&nbsp;';
984 }
985 print '</td></tr>';
986
987 //Add user to select destinaries list
988 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>';
989 //Disable autoselect to
990 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>';
991
992 print '</table>';
993 print '</div>';
994
995
996 print dol_get_fiche_end();
997
998
999 // Actions button
1000 print '<div class="tabsAction">';
1001
1002 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
1003
1004 if (!getDolGlobalString('MAIN_DISABLE_ALL_MAILS')) {
1005 if (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') != 'mail' || !$linuxlike) {
1006 if (function_exists('fsockopen') /* && $port && $server */) { // $port and $server can't be empty
1007 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect&token='.newToken().'&date='.dol_now().'#formmailaftertstconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
1008 }
1009 } else {
1010 //print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
1011 }
1012
1013 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&token='.newToken().'&mode=init#formmailbeforetitle">'.$langs->trans("DoTestSend").'</a>';
1014
1015 if (isModEnabled('fckeditor')) {
1016 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testhtml&token='.newToken().'&mode=init#formmailbeforetitle">'.$langs->trans("DoTestSendHTML").'</a>';
1017 }
1018 }
1019
1020 print '</div>';
1021
1022 if (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail' && !getDolGlobalString('MAIN_FIX_FOR_BUGGED_MTA')) {
1023 /*
1024 // Warning 1
1025 if ($linuxlike)
1026 {
1027 $sendmailoption=ini_get('mail.force_extra_parameters');
1028 if (empty($sendmailoption) || ! preg_match('/ba/',$sendmailoption))
1029 {
1030 print info_admin($langs->trans("SendmailOptionNotComplete"));
1031 }
1032 }*/
1033 // Warning 2
1034 print info_admin($langs->trans("SendmailOptionMayHurtBuggedMTA"));
1035 }
1036
1037 if (!in_array($action, array('testconnect', 'test', 'testhtml')) && !getDolGlobalString('MAIN_DISABLE_ALL_MAILS')) {
1038 $text = '';
1039 //if (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail') {
1040 // $text .= $langs->trans("WarningPHPMail", $listofmethods['mail'], $listofmethods['smtps']); // To encourage to use SMTPS
1041 //}
1042
1043 if (getDolGlobalString('MAIN_MAIL_SENDMODE', 'mail') == 'mail') {
1044 // mthode php mail
1045 if (getDolGlobalString('MAIN_EXTERNAL_MAIL_SPF_STRING_TO_ADD')) { // Not defined by default. Depend on platform.
1046 // List of string to add in SPF if the setup use the mail method. Example 'include:sendgrid.net include:spf.mydomain.com'
1047 $text .= /* ($text ? '<br><br>' : ''). */$langs->trans("WarningPHPMailSPFDMARC");
1048 } else {
1049 // MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS is list of IPs where email is sent from. Example: '1.2.3.4, [aaaa:bbbb:cccc:dddd]'.
1050 if (getDolGlobalString('MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS')) {
1051 // List of IP shown as record to add in SPF if we use the mail method
1052 $text .= /* ($text ? '<br><br>' : ''). */$langs->trans("WarningPHPMailSPFDMARC");
1053 }
1054 }
1055 } else {
1056 // method smtps or swiftmail
1057 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.
1058 // List of string to add in SPF if we use the smtp method. Example 'include:spf.mydomain.com'
1059 $text .= /* ($text ? '<br><br>' : ''). */$langs->trans("WarningPHPMailSPF", getDolGlobalString('MAIN_EXTERNAL_SMTP_SPF_STRING_TO_ADD'));
1060 }
1061 if (getDolGlobalString('MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS')) { // Not defined by default. Depend on platform.
1062 // 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]'
1063 // TODO Add a key to allow to show the IP/name of server detected dynamically
1064 $text .= ($text ? '<br><br>' : '').$langs->trans("WarningPHPMail2", getDolGlobalString('MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS'));
1065 }
1066 }
1067
1068 // Build list of main email addresses in $emailstotest and their domain to test in $domainstotest
1069 $emailstotest = array();
1070 if (getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')) {
1071 $emailstotest[getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')] = getDomainFromURL(preg_replace('/^.*@/', '', getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')), 1);
1072 }
1073 if (getDolGlobalString('MAIN_MAIL_EMAIL_FROM')) {
1074 $emailstotest[getDolGlobalString('MAIN_MAIL_EMAIL_FROM')] = getDomainFromURL(preg_replace('/^.*@/', '', getDolGlobalString('MAIN_MAIL_EMAIL_FROM')), 1);
1075 }
1076 if (!empty($user->email)) {
1077 $emailstotest[$user->email] = getDomainFromURL(preg_replace('/^.*@/', '', $user->email), 1);
1078 }
1079 $domainstotest = array();
1080 foreach ($emailstotest as $email => $domain) {
1081 if (empty($domainstotest[$domain])) {
1082 $domainstotest[$domain] = array($email => $email);
1083 } else {
1084 $domainstotest[$domain][$email] = $email;
1085 }
1086 }
1087
1088 // Test DNS entry for emails
1089 foreach (array('SPF', 'DMARC') as $dnstype) {
1090 foreach ($domainstotest as $domaintotest => $listofemails) {
1091 $dnsinfo = false;
1092 $foundforemail = 0;
1093 if (!empty($domaintotest) && function_exists('dns_get_record') && !getDolGlobalString('MAIN_DISABLE_DNS_GET_RECORD')) {
1094 $domain = $domaintotest;
1095 if ($dnstype == 'DMARC') {
1096 $domain = '_dmarc.'.$domain;
1097 }
1098 $dnsinfo = dns_get_record($domain, DNS_TXT);
1099 }
1100 if (!empty($dnsinfo) && is_array($dnsinfo)) {
1101 foreach ($dnsinfo as $info) {
1102 if (($dnstype == 'SPF' && stripos($info['txt'], 'v=spf') !== false)
1103 || ($dnstype == 'DMARC' && stripos($info['txt'], 'v=dmarc') !== false)) {
1104 $foundforemail++;
1105 $text .= ($text ? '<br>' : '').'- '.$langs->trans("ActualMailDNSRecordFound", '<b>'.$dnstype.'</b>', '<b>'.implode(', ', $listofemails).'</b>', '<span class="opacitylow">'.$info['txt'].'</span>');
1106 }
1107 }
1108 }
1109 if (!$foundforemail) {
1110 $text .= ($text ? '<br>' : '').'- '.$langs->trans("ActualMailDNSRecordFound", '<b>'.$dnstype.'</b>', '<b>'.implode(', ', $listofemails).'</b>', '<span class="opacitymedium">'.$langs->transnoentitiesnoconv("None").'</span>');
1111 }
1112 }
1113 }
1114
1115 if ($text) {
1116 print info_admin($langs->trans("SPFAndDMARCInformation").' :<br>'.$text, 0, 0, '1', '');
1117 }
1118 }
1119
1120 // Run the test to connect
1121 if ($action == 'testconnect') {
1122 print '<div id="formmailaftertstconnect" name="formmailaftertstconnect"></div>';
1123 print load_fiche_titre($langs->trans("DoTestServerAvailability"));
1124
1125 include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
1126 $mail = new CMailFile('', '', '', '', array(), array(), array(), '', '', 0, 0, '', '', '', $trackid, $sendcontext);
1127 $result = $mail->check_server_port($server, $port);
1128 if ($result) {
1129 print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort", $server, $port).'</div>';
1130 } else {
1131 $errormsg = $langs->trans("ServerNotAvailableOnIPOrPort", $server, $port);
1132
1133 if ($mail->error) {
1134 $errormsg .= ' - '.$mail->error;
1135 }
1136
1137 setEventMessages($errormsg, null, 'errors');
1138 }
1139 print '<br>';
1140 }
1141
1142 // Show email send test form
1143 if ($action == 'test' || $action == 'testhtml') {
1144 print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
1145 print load_fiche_titre($action == 'testhtml' ? $langs->trans("DoTestSendHTML") : $langs->trans("DoTestSend"));
1146
1147 print dol_get_fiche_head(array(), '', '', -1);
1148
1149 // Create form object
1150 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1151 $formmail = new FormMail($db);
1152 $formmail->trackid = (($action == 'testhtml') ? "testhtml" : "test");
1153 $formmail->fromname = (GETPOSTISSET('fromname') ? GETPOST('fromname') : getDolGlobalString('MAIN_MAIL_EMAIL_FROM'));
1154 $formmail->frommail = (GETPOSTISSET('frommail') ? GETPOST('frommail') : getDolGlobalString('MAIN_MAIL_EMAIL_FROM'));
1155 $formmail->fromid = $user->id;
1156 $formmail->fromalsorobot = 1;
1157 $formmail->fromtype = (GETPOSTISSET('fromtype') ? GETPOST('fromtype', 'aZ09') : getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE', 'user'));
1158 $formmail->withfromreadonly = 1;
1159 $formmail->withsubstit = 1;
1160 $formmail->withfrom = 1;
1161 $formmail->witherrorsto = 1;
1162 $formmail->withto = (GETPOSTISSET('sendto') ? GETPOST('sendto', 'restricthtml') : ($user->email ? $user->email : 1));
1163 $formmail->withtocc = (GETPOSTISSET('sendtocc') ? GETPOST('sendtocc', 'restricthtml') : 1); // ! empty to keep field if empty
1164 $formmail->withtoccc = (GETPOSTISSET('sendtoccc') ? GETPOST('sendtoccc', 'restricthtml') : 1); // ! empty to keep field if empty
1165 $formmail->withtopic = (GETPOSTISSET('subject') ? GETPOST('subject') : $langs->trans("Test"));
1166 $formmail->withtopicreadonly = 0;
1167 $formmail->withfile = 2;
1168
1169 $formmail->withlayout = 'emailing'; // Note: MAIN_EMAIL_USE_LAYOUT must be set
1170 $formmail->withaiprompt = ($action == 'testhtml' ? 'html' : 'text'); // Note: Module AI must be enabled
1171
1172 $formmail->withbody = (GETPOSTISSET('message') ? GETPOST('message', 'restricthtml') : ($action == 'testhtml' ? $langs->transnoentities("PredefinedMailTestHtml") : $langs->transnoentities("PredefinedMailTest")));
1173 $formmail->withbodyreadonly = 0;
1174 $formmail->withcancel = 1;
1175 $formmail->withdeliveryreceipt = 1;
1176 $formmail->withfckeditor = ($action == 'testhtml' ? 1 : 0);
1177 $formmail->ckeditortoolbar = 'dolibarr_mailings';
1178 // Array of substitutions
1179 $formmail->substit = $substitutionarrayfortest;
1180 // Array of complementary POST parameters
1181 $formmail->param["action"] = "send";
1182 $formmail->param["models"] = "body";
1183 $formmail->param["mailid"] = 0;
1184 $formmail->param["returnurl"] = $_SERVER["PHP_SELF"];
1185
1186 // Init list of files
1187 if (GETPOST("mode", "aZ09") == 'init') {
1188 $formmail->clear_attached_files();
1189 }
1190
1191 print $formmail->get_form('addfile', 'removefile');
1192
1193 print dol_get_fiche_end();
1194
1195 // References
1196 if (!empty($user->admin)) {
1197 print '<br><br>';
1198 print '<span class="opacitymedium">'.$langs->trans("EMailsWillHaveMessageID").': ';
1199 print dol_escape_htmltag('<timestamp.*@'.dol_getprefix('email').'>');
1200 print '</span>';
1201 }
1202 }
1203}
1204
1205// End of page
1206llxFooter();
1207$db->close();
$id
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.
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:71
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...
llxFooter()
Footer empty.
Definition document.php:107
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)
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.
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)
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.