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