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