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