dolibarr  16.0.5
mails.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2020 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
5  * Copyright (C) 2016 Jonathan TISSEAU <jonathan.tisseau@86dev.fr>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
29 
30 // Load translation files required by the page
31 $langs->loadLangs(array("companies", "products", "admin", "mails", "other", "errors"));
32 
33 $action = GETPOST('action', 'aZ09');
34 $cancel = GETPOST('cancel', 'aZ09');
35 
36 if (!$user->admin) {
38 }
39 
40 $usersignature = $user->signature;
41 // For action = test or send, we ensure that content is not html, even for signature, because this we want a test with NO html.
42 
43 if ($action == 'test' || $action == 'send') {
44  $usersignature = dol_string_nohtmltag($usersignature, 2);
45 }
46 
47 $substitutionarrayfortest = array(
48  '__DOL_MAIN_URL_ROOT__'=>DOL_MAIN_URL_ROOT,
49  '__CHECK_READ__' => (!empty($object) && is_object($object) && is_object($object->thirdparty)) ? '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$object->thirdparty->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>' : '',
50  '__USER_LOGIN__' => $user->login,
51  '__USER_EMAIL__' => $user->email,
52  '__USER_SIGNATURE__' => (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $usersignature : ''), // Done into actions_sendmails
53  '__ID__' => 'RecipientIdRecord',
54  //'__EMAIL__' => 'RecipientEMail', // Done into actions_sendmails
55  '__LASTNAME__' => 'RecipientLastname',
56  '__FIRSTNAME__' => 'RecipientFirstname',
57  '__ADDRESS__'=> 'RecipientAddress',
58  '__ZIP__'=> 'RecipientZip',
59  '__TOWN_'=> 'RecipientTown',
60  '__COUNTRY__'=> 'RecipientCountry'
61 );
62 complete_substitutions_array($substitutionarrayfortest, $langs);
63 
64 
65 
66 /*
67  * Actions
68  */
69 
70 if ($action == 'update' && !$cancel) {
71  if (!$error && !GETPOST("MAIN_MAIL_EMAIL_FROM", 'alphanohtml')) {
72  $error++;
73  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("MAIN_MAIL_EMAIL_FROM")), null, 'errors');
74  $action = 'edit';
75  }
76  if (!$error && !isValidEmail(GETPOST("MAIN_MAIL_EMAIL_FROM", 'alphanohtml'))) {
77  $error++;
78  setEventMessages($langs->trans("ErrorBadEMail", GETPOST("MAIN_MAIL_EMAIL_FROM", 'alphanohtml')), null, 'errors');
79  $action = 'edit';
80  }
81 
82  if (!$error) {
83  dolibarr_set_const($db, "MAIN_DISABLE_ALL_MAILS", GETPOST("MAIN_DISABLE_ALL_MAILS", 'int'), 'chaine', 0, '', $conf->entity);
84  dolibarr_set_const($db, "MAIN_MAIL_FORCE_SENDTO", GETPOST("MAIN_MAIL_FORCE_SENDTO", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
85  dolibarr_set_const($db, "MAIN_MAIL_ENABLED_USER_DEST_SELECT", GETPOST("MAIN_MAIL_ENABLED_USER_DEST_SELECT", 'int'), 'chaine', 0, '', $conf->entity);
86  // Send mode parameters
87  dolibarr_set_const($db, "MAIN_MAIL_SENDMODE", GETPOST("MAIN_MAIL_SENDMODE", 'aZ09'), 'chaine', 0, '', $conf->entity);
88  dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT", GETPOST("MAIN_MAIL_SMTP_PORT", 'int'), 'chaine', 0, '', $conf->entity);
89  dolibarr_set_const($db, "MAIN_MAIL_SMTP_SERVER", GETPOST("MAIN_MAIL_SMTP_SERVER", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
90  dolibarr_set_const($db, "MAIN_MAIL_SMTPS_ID", GETPOST("MAIN_MAIL_SMTPS_ID", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
91  dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW", GETPOST("MAIN_MAIL_SMTPS_PW", 'none'), 'chaine', 0, '', $conf->entity);
92  dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS", GETPOST("MAIN_MAIL_EMAIL_TLS", 'int'), 'chaine', 0, '', $conf->entity);
93  dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS", GETPOST("MAIN_MAIL_EMAIL_STARTTLS", 'int'), 'chaine', 0, '', $conf->entity);
94  dolibarr_set_const($db, "MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED", GETPOST("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED", 'int'), 'chaine', 0, '', $conf->entity);
95 
96  dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_ENABLED", GETPOST("MAIN_MAIL_EMAIL_DKIM_ENABLED", 'int'), 'chaine', 0, '', $conf->entity);
97  dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_DOMAIN", GETPOST("MAIN_MAIL_EMAIL_DKIM_DOMAIN", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
98  dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_SELECTOR", GETPOST("MAIN_MAIL_EMAIL_DKIM_SELECTOR", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
99  dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY", GETPOST("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
100  // Content parameters
101  dolibarr_set_const($db, "MAIN_MAIL_EMAIL_FROM", GETPOST("MAIN_MAIL_EMAIL_FROM", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
102  dolibarr_set_const($db, "MAIN_MAIL_ERRORS_TO", GETPOST("MAIN_MAIL_ERRORS_TO", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
103  dolibarr_set_const($db, "MAIN_MAIL_AUTOCOPY_TO", GETPOST("MAIN_MAIL_AUTOCOPY_TO", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
104  dolibarr_set_const($db, 'MAIN_MAIL_DEFAULT_FROMTYPE', GETPOST('MAIN_MAIL_DEFAULT_FROMTYPE', 'alphanohtml'), 'chaine', 0, '', $conf->entity);
105 
106  header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
107  exit;
108  }
109 }
110 
111 
112 // Actions to send emails
113 $id = 0;
114 $actiontypecode = ''; // Not an event for agenda
115 $triggersendname = ''; // Disable triggers
116 $paramname = 'id';
117 $mode = 'emailfortest';
118 $trackid = (($action == 'testhtml') ? "testhtml" : "test");
119 $sendcontext = '';
120 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
121 
122 if ($action == 'presend' && GETPOST('trackid', 'alphanohtml') == 'test') {
123  $action = 'test';
124 }
125 if ($action == 'presend' && GETPOST('trackid', 'alphanohtml') == 'testhtml') {
126  $action = 'testhtml';
127 }
128 
129 
130 
131 
132 /*
133  * View
134  */
135 
136 $form = new Form($db);
137 
138 $linuxlike = 1;
139 if (preg_match('/^win/i', PHP_OS)) {
140  $linuxlike = 0;
141 }
142 if (preg_match('/^mac/i', PHP_OS)) {
143  $linuxlike = 0;
144 }
145 
146 if (empty($conf->global->MAIN_MAIL_SENDMODE)) {
147  $conf->global->MAIN_MAIL_SENDMODE = 'mail';
148 }
149 $port = !empty($conf->global->MAIN_MAIL_SMTP_PORT) ? $conf->global->MAIN_MAIL_SMTP_PORT : ini_get('smtp_port');
150 if (!$port) {
151  $port = 25;
152 }
153 $server = !empty($conf->global->MAIN_MAIL_SMTP_SERVER) ? $conf->global->MAIN_MAIL_SMTP_SERVER : ini_get('SMTP');
154 if (!$server) {
155  $server = '127.0.0.1';
156 }
157 
158 
159 $wikihelp = 'EN:Setup_EMails|FR:Paramétrage_EMails|ES:Configuración_EMails';
160 llxHeader('', $langs->trans("Setup"), $wikihelp);
161 
162 print load_fiche_titre($langs->trans("EMailsSetup"), '', 'title_setup');
163 
164 $head = email_admin_prepare_head();
165 
166 // List of sending methods
167 $listofmethods = array();
168 $listofmethods['mail'] = 'PHP mail function';
169 $listofmethods['smtps'] = 'SMTP/SMTPS socket library';
170 if (version_compare(phpversion(), '7.0', '>=')) {
171  $listofmethods['swiftmailer'] = 'Swift Mailer socket library';
172 }
173 
174 
175 if ($action == 'edit') {
176  if ($conf->use_javascript_ajax) {
177  print "\n".'<script type="text/javascript">';
178  print 'jQuery(document).ready(function () {
179  function initfields()
180  {
181  if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'mail\')
182  {
183  console.log("I choose php mail mode");
184  jQuery(".drag").hide();
185  jQuery("#MAIN_MAIL_EMAIL_TLS").val(0);
186  jQuery("#MAIN_MAIL_EMAIL_TLS").prop("disabled", true);
187  jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val(0);
188  jQuery("#MAIN_MAIL_EMAIL_STARTTLS").prop("disabled", true);
189  jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val(0);
190  jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").prop("disabled", true);
191  jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val(0);
192  jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").prop("disabled", true);
193  jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").prop("disabled", true);
194  jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").prop("disabled", true);
195  jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").prop("disabled", true);
196  jQuery(".smtp_method").hide();
197  jQuery(".dkim").hide();
198  ';
199  if ($linuxlike) {
200  print '
201  jQuery("#MAIN_MAIL_SMTP_SERVER").hide();
202  jQuery("#MAIN_MAIL_SMTP_PORT").hide();
203  jQuery("#smtp_server_mess").show();
204  jQuery("#smtp_port_mess").show();';
205  } else {
206  print '
207  jQuery("#MAIN_MAIL_SMTP_SERVER").prop("disabled", true);
208  jQuery("#MAIN_MAIL_SMTP_PORT").prop("disabled", true);
209  jQuery("#smtp_server_mess").hide();
210  jQuery("#smtp_port_mess").hide();';
211  }
212  print '
213  }
214  if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'smtps\')
215  {
216  console.log("I choose smtps mode");
217  jQuery(".drag").show();
218  jQuery("#MAIN_MAIL_EMAIL_TLS").val('.$conf->global->MAIN_MAIL_EMAIL_TLS.');
219  jQuery("#MAIN_MAIL_EMAIL_TLS").removeAttr("disabled");
220  jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS.');
221  jQuery("#MAIN_MAIL_EMAIL_STARTTLS").removeAttr("disabled");
222  jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val('.$conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED.');
223  jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").removeAttr("disabled");
224  jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val(0);
225  jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").prop("disabled", true);
226  jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").prop("disabled", true);
227  jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").prop("disabled", true);
228  jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").prop("disabled", true);
229  jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").hide();
230  jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").hide();
231  jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").hide();
232  jQuery("#MAIN_MAIL_SMTP_SERVER").removeAttr("disabled");
233  jQuery("#MAIN_MAIL_SMTP_PORT").removeAttr("disabled");
234  jQuery("#MAIN_MAIL_SMTP_SERVER").show();
235  jQuery("#MAIN_MAIL_SMTP_PORT").show();
236  jQuery("#smtp_server_mess").hide();
237  jQuery("#smtp_port_mess").hide();
238  jQuery(".smtp_method").show();
239  jQuery(".dkim").hide();
240  }
241  if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'swiftmailer\')
242  {
243  console.log("I choose swiftmailer mode");
244  jQuery(".drag").show();
245  jQuery("#MAIN_MAIL_EMAIL_TLS").val('.$conf->global->MAIN_MAIL_EMAIL_TLS.');
246  jQuery("#MAIN_MAIL_EMAIL_TLS").removeAttr("disabled");
247  jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS.');
248  jQuery("#MAIN_MAIL_EMAIL_STARTTLS").removeAttr("disabled");
249  jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val('.$conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED.');
250  jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").removeAttr("disabled");
251  jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val('.$conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED.');
252  jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").removeAttr("disabled");
253  jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").removeAttr("disabled");
254  jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").removeAttr("disabled");
255  jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").removeAttr("disabled");
256  jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").show();
257  jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").show();
258  jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").show();
259  jQuery("#MAIN_MAIL_SMTP_SERVER").removeAttr("disabled");
260  jQuery("#MAIN_MAIL_SMTP_PORT").removeAttr("disabled");
261  jQuery("#MAIN_MAIL_SMTP_SERVER").show();
262  jQuery("#MAIN_MAIL_SMTP_PORT").show();
263  jQuery("#smtp_server_mess").hide();
264  jQuery("#smtp_port_mess").hide();
265  jQuery(".smtp_method").show();
266  jQuery(".dkim").show();
267  }
268  }
269  initfields();
270  jQuery("#MAIN_MAIL_SENDMODE").change(function() {
271  initfields();
272  });
273  jQuery("#MAIN_MAIL_EMAIL_TLS").change(function() {
274  if (jQuery("#MAIN_MAIL_EMAIL_TLS").val() == 1)
275  jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val(0);
276  else
277  jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val(0);
278  });
279  jQuery("#MAIN_MAIL_EMAIL_STARTTLS").change(function() {
280  if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val() == 1)
281  jQuery("#MAIN_MAIL_EMAIL_TLS").val(0);
282  else
283  jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val(0);
284  });
285  })';
286  print '</script>'."\n";
287  }
288 
289  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
290  print '<input type="hidden" name="token" value="'.newToken().'">';
291  print '<input type="hidden" name="action" value="update">';
292 
293  print dol_get_fiche_head($head, 'common', '', -1);
294 
295  print '<span class="opacitymedium">'.$langs->trans("EMailsDesc")."</span><br>\n";
296  print "<br><br>\n";
297 
298 
299  clearstatcache();
300 
301  print '<table class="noborder centpercent">';
302  print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
303 
304  // Disable
305  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_MAILS").'</td><td>';
306  print $form->selectyesno('MAIN_DISABLE_ALL_MAILS', getDolGlobalString('MAIN_DISABLE_ALL_MAILS'), 1);
307  print '</td></tr>';
308 
309  // Force e-mail recipient
310  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_FORCE_SENDTO").'</td><td>';
311  print '<input class="flat" name="MAIN_MAIL_FORCE_SENDTO" size="32" value="'.(!empty($conf->global->MAIN_MAIL_FORCE_SENDTO) ? $conf->global->MAIN_MAIL_FORCE_SENDTO : '').'" />';
312  print '</td></tr>';
313 
314  print '</table>';
315 
316  print '<br>';
317 
318  print '<table class="noborder centpercent">';
319  print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td></td></tr>';
320 
321  // Method
322  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
323 
324  // SuperAdministrator access only
325  if ((empty($conf->global->MAIN_MODULE_MULTICOMPANY)) || ($user->admin && !$user->entity)) {
326  print $form->selectarray('MAIN_MAIL_SENDMODE', $listofmethods, $conf->global->MAIN_MAIL_SENDMODE);
327  } else {
328  $text = $listofmethods[$conf->global->MAIN_MAIL_SENDMODE];
329  if (empty($text)) {
330  $text = $langs->trans("Undefined");
331  }
332  $htmltext = $langs->trans("ContactSuperAdminForChange");
333  print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
334  print '<input type="hidden" name="MAIN_MAIL_SENDMODE" value="'.$conf->global->MAIN_MAIL_SENDMODE.'">';
335  }
336  print '</td></tr>';
337 
338  // Host server
339  print '<tr class="oddeven">';
340  if (!$conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE == 'mail') {
341  print '<td>';
342  print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
343  print '</td><td>';
344  print '<span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
345  print '</td>';
346  } else {
347  print '<td>';
348  $mainserver = (!empty($conf->global->MAIN_MAIL_SMTP_SERVER) ? $conf->global->MAIN_MAIL_SMTP_SERVER : '');
349  $smtpserver = ini_get('SMTP') ?ini_get('SMTP') : $langs->transnoentities("Undefined");
350  if ($linuxlike) {
351  print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
352  } else {
353  print $langs->trans("MAIN_MAIL_SMTP_SERVER", $smtpserver);
354  }
355  print '</td><td>';
356  // SuperAdministrator access only
357  if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity)) {
358  print '<input class="flat minwidth300" id="MAIN_MAIL_SMTP_SERVER" name="MAIN_MAIL_SMTP_SERVER" value="'.$mainserver.'" autocomplete="off">';
359  print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_sav" name="MAIN_MAIL_SMTP_SERVER_sav" value="'.$mainserver.'">';
360  print '<span id="smtp_server_mess" class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
361  print ' <span class="opacitymedium smtp_method">'.$langs->trans("SeeLinkToOnlineDocumentation").'</span>';
362  } else {
363  $text = !empty($mainserver) ? $mainserver : $smtpserver;
364  $htmltext = $langs->trans("ContactSuperAdminForChange");
365  print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
366  print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER" name="MAIN_MAIL_SMTP_SERVER" value="'.$mainserver.'">';
367  }
368  print '</td>';
369  }
370  print '</tr>';
371 
372  // Port
373  print '<tr class="oddeven"><td>';
374  if (!$conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE == 'mail') {
375  print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
376  print '</td><td>';
377  print '<span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
378  } else {
379  $mainport = (!empty($conf->global->MAIN_MAIL_SMTP_PORT) ? $conf->global->MAIN_MAIL_SMTP_PORT : '');
380  $smtpport = ini_get('smtp_port') ?ini_get('smtp_port') : $langs->transnoentities("Undefined");
381  if ($linuxlike) {
382  print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
383  } else {
384  print $langs->trans("MAIN_MAIL_SMTP_PORT", $smtpport);
385  }
386  print '</td><td>';
387  // SuperAdministrator access only
388  if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity)) {
389  print '<input class="flat" id="MAIN_MAIL_SMTP_PORT" name="MAIN_MAIL_SMTP_PORT" size="3" value="'.$mainport.'">';
390  print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_sav" name="MAIN_MAIL_SMTP_PORT_sav" value="'.$mainport.'">';
391  print '<span id="smtp_port_mess" class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
392  } else {
393  $text = (!empty($mainport) ? $mainport : $smtpport);
394  $htmltext = $langs->trans("ContactSuperAdminForChange");
395  print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
396  print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT" name="MAIN_MAIL_SMTP_PORT" value="'.$mainport.'">';
397  }
398  }
399  print '</td></tr>';
400 
401  // ID
402  if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))) {
403  $mainstmpid = (!empty($conf->global->MAIN_MAIL_SMTPS_ID) ? $conf->global->MAIN_MAIL_SMTPS_ID : '');
404  print '<tr class="drag drop oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>';
405  // SuperAdministrator access only
406  if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity)) {
407  print '<input class="flat" name="MAIN_MAIL_SMTPS_ID" size="32" value="'.$mainstmpid.'">';
408  } else {
409  $htmltext = $langs->trans("ContactSuperAdminForChange");
410  print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_ID, $htmltext, 1, 'superadmin');
411  print '<input type="hidden" name="MAIN_MAIL_SMTPS_ID" value="'.$mainstmpid.'">';
412  }
413  print '</td></tr>';
414  }
415 
416  // PW
417  if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))) {
418  $mainsmtppw = (!empty($conf->global->MAIN_MAIL_SMTPS_PW) ? $conf->global->MAIN_MAIL_SMTPS_PW : '');
419  print '<tr class="drag drop oddeven"><td>';
420  print $form->textwithpicto($langs->trans("MAIN_MAIL_SMTPS_PW"), $langs->trans("WithGMailYouCanCreateADedicatedPassword"));
421  print '</td><td>';
422  // SuperAdministrator access only
423  if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity)) {
424  print '<input class="flat" type="password" name="MAIN_MAIL_SMTPS_PW" size="32" value="' . htmlspecialchars($mainsmtppw, ENT_COMPAT, 'UTF-8') . '" autocomplete="off">';
425  } else {
426  $htmltext = $langs->trans("ContactSuperAdminForChange");
427  print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_PW, $htmltext, 1, 'superadmin');
428  print '<input type="hidden" name="MAIN_MAIL_SMTPS_PW" value="' . htmlspecialchars($mainsmtppw, ENT_COMPAT, 'UTF-8') . '">';
429  }
430  print '</td></tr>';
431  }
432 
433  // TLS
434  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
435  if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))) {
436  if (function_exists('openssl_open')) {
437  print $form->selectyesno('MAIN_MAIL_EMAIL_TLS', (!empty($conf->global->MAIN_MAIL_EMAIL_TLS) ? $conf->global->MAIN_MAIL_EMAIL_TLS : 0), 1);
438  } else {
439  print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
440  }
441  } else {
442  print yn(0).' ('.$langs->trans("NotSupported").')';
443  }
444  print '</td></tr>';
445 
446  // STARTTLS
447  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
448  if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))) {
449  if (function_exists('openssl_open')) {
450  print $form->selectyesno('MAIN_MAIL_EMAIL_STARTTLS', (!empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS) ? $conf->global->MAIN_MAIL_EMAIL_STARTTLS : 0), 1);
451  } else {
452  print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
453  }
454  } else {
455  print yn(0).' ('.$langs->trans("NotSupported").')';
456  }
457  print '</td></tr>';
458 
459  // SMTP_ALLOW_SELF_SIGNED
460  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").'</td><td>';
461  if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))) {
462  if (function_exists('openssl_open')) {
463  print $form->selectyesno('MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED', (!empty($conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED) ? $conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED : 0), 1);
464  } else {
465  print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
466  }
467  } else {
468  print yn(0).' ('.$langs->trans("NotSupported").')';
469  }
470  print '</td></tr>';
471 
472  // DKIM
473  print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_ENABLED").'</td><td>';
474  if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('swiftmailer')))) {
475  if (function_exists('openssl_open')) {
476  print $form->selectyesno('MAIN_MAIL_EMAIL_DKIM_ENABLED', (!empty($conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED) ? $conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED : 0), 1);
477  } else {
478  print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
479  }
480  } else {
481  print yn(0).' ('.$langs->trans("NotSupported").')';
482  }
483  print '</td></tr>';
484 
485  // DKIM Domain
486  print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_DOMAIN").'</td>';
487  print '<td><input class="flat" id="MAIN_MAIL_EMAIL_DKIM_DOMAIN" name="MAIN_MAIL_EMAIL_DKIM_DOMAIN" size="32" value="'.(!empty($conf->global->MAIN_MAIL_EMAIL_DKIM_DOMAIN) ? $conf->global->MAIN_MAIL_EMAIL_DKIM_DOMAIN : '');
488  print '"></td></tr>';
489 
490  // DKIM Selector
491  print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_SELECTOR").'</td>';
492  print '<td><input class="flat" id="MAIN_MAIL_EMAIL_DKIM_SELECTOR" name="MAIN_MAIL_EMAIL_DKIM_SELECTOR" size="32" value="'.(!empty($conf->global->MAIN_MAIL_EMAIL_DKIM_SELECTOR) ? $conf->global->MAIN_MAIL_EMAIL_DKIM_SELECTOR : '');
493  print '"></td></tr>';
494 
495  // DKIM PRIVATE KEY
496  print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").'</td>';
497  print '<td><textarea id="MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY" name="MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY" rows="15" cols="100">'.(!empty($conf->global->MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY) ? $conf->global->MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY : '').'</textarea>';
498  print '</td></tr>';
499 
500  print '</table>';
501 
502  print '<br>';
503 
504  print '<table class="noborder centpercent">';
505  print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("OtherOptions").'</td><td></td></tr>';
506 
507  // From
508  $help = img_help(1, $langs->trans("EMailHelpMsgSPFDKIM"));
509  print '<tr class="oddeven"><td class="fieldrequired">'.$langs->trans("MAIN_MAIL_EMAIL_FROM", ini_get('sendmail_from') ?ini_get('sendmail_from') : $langs->transnoentities("Undefined")).' '.$help.'</td>';
510  print '<td><input class="flat minwidth200" name="MAIN_MAIL_EMAIL_FROM" value="'.(!empty($conf->global->MAIN_MAIL_EMAIL_FROM) ? $conf->global->MAIN_MAIL_EMAIL_FROM : '');
511  print '"></td></tr>';
512 
513  // Default from type
514  $liste = array();
515  $liste['user'] = $langs->trans('UserEmail');
516  $liste['company'] = $langs->trans('CompanyEmail').' ('.(empty($conf->global->MAIN_INFO_SOCIETE_MAIL) ? $langs->trans("NotDefined") : $conf->global->MAIN_INFO_SOCIETE_MAIL).')';
517 
518  print '<tr class="oddeven"><td>'.$langs->trans('MAIN_MAIL_DEFAULT_FROMTYPE').'</td><td>';
519  print $form->selectarray('MAIN_MAIL_DEFAULT_FROMTYPE', $liste, getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE'), 0);
520  print '</td></tr>';
521 
522  // From
523  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ERRORS_TO").'</td>';
524  print '<td><input class="flat" name="MAIN_MAIL_ERRORS_TO" size="32" value="'.(!empty($conf->global->MAIN_MAIL_ERRORS_TO) ? $conf->global->MAIN_MAIL_ERRORS_TO : '');
525  print '"></td></tr>';
526 
527  // Autocopy to
528  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
529  print '<td><input class="flat" name="MAIN_MAIL_AUTOCOPY_TO" size="32" value="'.(!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO) ? $conf->global->MAIN_MAIL_AUTOCOPY_TO : '');
530  print '"></td></tr>';
531 
532  // Add user to select destinaries list
533  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ENABLED_USER_DEST_SELECT").'</td><td>';
534  print $form->selectyesno('MAIN_MAIL_ENABLED_USER_DEST_SELECT', getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT'), 1);
535  print '</td></tr>';
536 
537  print '</table>';
538 
539  print dol_get_fiche_end();
540 
541  print $form->buttonsSaveCancel();
542 
543  print '</form>';
544 } else {
545  print dol_get_fiche_head($head, 'common', '', -1);
546 
547  print '<span class="opacitymedium">'.$langs->trans("EMailsDesc")."</span><br>\n";
548  print "<br><br>\n";
549 
550  print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
551  print '<table class="noborder centpercent">';
552  print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
553 
554  // Disable
555  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_MAILS").'</td><td>'.yn(!empty($conf->global->MAIN_DISABLE_ALL_MAILS));
556  if (!empty($conf->global->MAIN_DISABLE_ALL_MAILS)) {
557  print img_warning($langs->trans("Disabled"));
558  }
559  print '</td></tr>';
560 
561  if (empty($conf->global->MAIN_DISABLE_ALL_MAILS)) {
562  // Force e-mail recipient
563  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_FORCE_SENDTO").'</td><td>'.getDolGlobalString('MAIN_MAIL_FORCE_SENDTO');
564  if (!empty(getDolGlobalString('MAIN_MAIL_FORCE_SENDTO'))) {
565  if (!isValidEmail(getDolGlobalString('MAIN_MAIL_FORCE_SENDTO'))) {
566  print img_warning($langs->trans("ErrorBadEMail"));
567  } else {
568  print img_warning($langs->trans("RecipientEmailsWillBeReplacedWithThisValue"));
569  }
570  }
571  print '</td></tr>';
572  }
573 
574  print '</table>';
575  print '</div>';
576 
577  if (empty($conf->global->MAIN_DISABLE_ALL_MAILS)) {
578  print '<br>';
579 
580  print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
581  print '<table class="noborder centpercent">';
582  print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td></td></tr>';
583 
584  // Method
585  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
586  $text = $listofmethods[$conf->global->MAIN_MAIL_SENDMODE];
587  if (empty($text)) {
588  $text = $langs->trans("Undefined").img_warning();
589  }
590  print $text;
591 
592  if ($conf->global->MAIN_MAIL_SENDMODE == 'mail' && empty($conf->global->MAIN_HIDE_WARNING_TO_ENCOURAGE_SMTP_SETUP)) {
593  print $form->textwithpicto('', $langs->trans("WarningPHPMail").'<br>'.$langs->trans("WarningPHPMailA").'<br>'.$langs->trans("WarningPHPMailB").'<br>'.$langs->trans("WarningPHPMailC").'<br><br>'.$langs->trans("WarningPHPMailD"), 1, 'warning');
594  }
595 
596  print '</td></tr>';
597 
598  // Host server
599  if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'mail')) {
600  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike").'</td><td><span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span></td></tr>';
601  } else {
602  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER", ini_get('SMTP') ?ini_get('SMTP') : $langs->transnoentities("Undefined")).'</td><td>'.(!empty($conf->global->MAIN_MAIL_SMTP_SERVER) ? $conf->global->MAIN_MAIL_SMTP_SERVER : '').'</td></tr>';
603  }
604 
605  // Port
606  if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'mail')) {
607  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").'</td><td><span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span></td></tr>';
608  } else {
609  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT", ini_get('smtp_port') ?ini_get('smtp_port') : $langs->transnoentities("Undefined")).'</td><td>'.(!empty($conf->global->MAIN_MAIL_SMTP_PORT) ? $conf->global->MAIN_MAIL_SMTP_PORT : '').'</td></tr>';
610  }
611 
612  // SMTPS ID
613  if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))) {
614  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>'.$conf->global->MAIN_MAIL_SMTPS_ID.'</td></tr>';
615  }
616 
617  // SMTPS PW
618  if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))) {
619  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>'.preg_replace('/./', '*', $conf->global->MAIN_MAIL_SMTPS_PW).'</td></tr>';
620  }
621 
622  // TLS
623  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
624  if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))) {
625  if (function_exists('openssl_open')) {
626  print yn($conf->global->MAIN_MAIL_EMAIL_TLS);
627  } else {
628  print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
629  }
630  } else {
631  print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
632  }
633  print '</td></tr>';
634 
635  // STARTTLS
636  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
637  if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))) {
638  if (function_exists('openssl_open')) {
639  print yn($conf->global->MAIN_MAIL_EMAIL_STARTTLS);
640  } else {
641  print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
642  }
643  } else {
644  print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
645  }
646  print '</td></tr>';
647 
648  // SMTP_ALLOW_SELF_SIGNED
649  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").'</td><td>';
650  if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))) {
651  if (function_exists('openssl_open')) {
652  print yn($conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED);
653  } else {
654  print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
655  }
656  } else {
657  print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
658  }
659  print '</td></tr>';
660 
661 
662  if ($conf->global->MAIN_MAIL_SENDMODE == 'swiftmailer') {
663  // DKIM
664  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_ENABLED").'</td><td>';
665  if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('swiftmailer'))) {
666  if (function_exists('openssl_open')) {
667  print yn(getDolGlobalInt('MAIN_MAIL_EMAIL_DKIM_ENABLED'));
668  } else {
669  print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
670  }
671  } else {
672  print yn(0).' ('.$langs->trans("NotSupported").')';
673  }
674  print '</td></tr>';
675 
676  // Domain
677  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_DOMAIN").'</td>';
678  print '<td>'.getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_DOMAIN');
679  print '</td></tr>';
680 
681  // Selector
682  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_SELECTOR").'</td>';
683  print '<td>'.getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_SELECTOR');
684  print '</td></tr>';
685 
686  // PRIVATE KEY
687  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").'</td>';
688  print '<td>'.getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY');
689  print '</td></tr>';
690  }
691 
692  print '</table>';
693  print '</div>';
694 
695  if ($conf->global->MAIN_MAIL_SENDMODE == 'mail' && empty($conf->global->MAIN_HIDE_WARNING_TO_ENCOURAGE_SMTP_SETUP)) {
696  print info_admin($langs->trans("WarningPHPMail").'<br>'.$langs->trans("WarningPHPMailA").'<br>'.$langs->trans("WarningPHPMailB").'<br>'.$langs->trans("WarningPHPMailC").'<br><br>'.$langs->trans("WarningPHPMailD"), 0, 0, 'warning');
697  }
698 
699  print '<br>';
700 
701  print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
702  print '<table class="noborder centpercent">';
703  print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("OtherOptions").'</td><td></td></tr>';
704 
705  // From
706  $help = img_help(1, $langs->trans("EMailHelpMsgSPFDKIM"));
707  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_FROM", ini_get('sendmail_from') ?ini_get('sendmail_from') : $langs->transnoentities("Undefined")).' '.$help.'</td>';
708  print '<td>'.$conf->global->MAIN_MAIL_EMAIL_FROM;
709  if (empty($conf->global->MAIN_MAIL_EMAIL_FROM)) {
710  print img_warning($langs->trans("Mandatory"));
711  } elseif (!isValidEmail($conf->global->MAIN_MAIL_EMAIL_FROM)) {
712  print img_warning($langs->trans("ErrorBadEMail"));
713  }
714  print '</td></tr>';
715 
716  // Default from type
717  $liste = array();
718  $liste['user'] = $langs->trans('UserEmail');
719  $liste['company'] = $langs->trans('CompanyEmail').' ('.(empty($conf->global->MAIN_INFO_SOCIETE_MAIL) ? $langs->trans("NotDefined") : $conf->global->MAIN_INFO_SOCIETE_MAIL).')';
720  $sql = 'SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile';
721  $sql .= ' WHERE active = 1 AND (private = 0 OR private = '.((int) $user->id).')';
722  $resql = $db->query($sql);
723  if ($resql) {
724  $num = $db->num_rows($resql);
725  $i = 0;
726  while ($i < $num) {
727  $obj = $db->fetch_object($resql);
728  if ($obj) {
729  $liste['senderprofile_'.$obj->rowid] = $obj->label.' <'.$obj->email.'>';
730  }
731  $i++;
732  }
733  } else {
734  dol_print_error($db);
735  }
736 
737  print '<tr class="oddeven"><td>'.$langs->trans('MAIN_MAIL_DEFAULT_FROMTYPE').'</td>';
738  print '<td>';
739  if (getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE') === 'robot') {
740  print $langs->trans('RobotEmail');
741  } elseif (getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE') === 'user') {
742  print $langs->trans('UserEmail');
743  } elseif (getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE') === 'company') {
744  print $langs->trans('CompanyEmail').' '.dol_escape_htmltag('<'.$mysoc->email.'>');
745  } else {
746  $id = preg_replace('/senderprofile_/', '', getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE'));
747  if ($id > 0) {
748  include_once DOL_DOCUMENT_ROOT.'/core/class/emailsenderprofile.class.php';
749  $emailsenderprofile = new EmailSenderProfile($db);
750  $emailsenderprofile->fetch($id);
751  print $emailsenderprofile->label.' '.dol_escape_htmltag('<'.$emailsenderprofile->email.'>');
752  }
753  }
754  print '</td></tr>';
755 
756  // Errors To
757  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ERRORS_TO").'</td>';
758  print '<td>'.(getDolGlobalString('MAIN_MAIL_ERRORS_TO'));
759  if (!empty($conf->global->MAIN_MAIL_ERRORS_TO) && !isValidEmail($conf->global->MAIN_MAIL_ERRORS_TO)) {
760  print img_warning($langs->trans("ErrorBadEMail"));
761  }
762  print '</td></tr>';
763 
764  // Autocopy to
765  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
766  print '<td>';
767  if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) {
768  $listofemail = explode(',', $conf->global->MAIN_MAIL_AUTOCOPY_TO);
769  $i = 0;
770  foreach ($listofemail as $key => $val) {
771  if ($i) {
772  print ', ';
773  }
774  $val = trim($val);
775  print $val;
776  if (!isValidEmail($val, 0, 1)) {
777  print img_warning($langs->trans("ErrorBadEMail", $val));
778  }
779  $i++;
780  }
781  } else {
782  print '&nbsp;';
783  }
784  print '</td></tr>';
785 
786  //Add user to select destinaries list
787  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ENABLED_USER_DEST_SELECT").'</td><td>'.yn(!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)).'</td></tr>';
788 
789  print '</table>';
790  print '</div>';
791  }
792 
793  print dol_get_fiche_end();
794 
795 
796  // Actions button
797  print '<div class="tabsAction">';
798 
799  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
800 
801  if (empty($conf->global->MAIN_DISABLE_ALL_MAILS)) {
802  if ($conf->global->MAIN_MAIL_SENDMODE != 'mail' || !$linuxlike) {
803  if (function_exists('fsockopen') && $port && $server) {
804  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect&date='.dol_now().'#formmailaftertstconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
805  }
806  } else {
807  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
808  }
809 
810  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&mode=init#formmailbeforetitle">'.$langs->trans("DoTestSend").'</a>';
811 
812  if (!empty($conf->fckeditor->enabled)) {
813  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testhtml&mode=init#formmailbeforetitle">'.$langs->trans("DoTestSendHTML").'</a>';
814  }
815  }
816 
817  print '</div>';
818 
819 
820  if ($conf->global->MAIN_MAIL_SENDMODE == 'mail' && empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)) {
821  /*
822  // Warning 1
823  if ($linuxlike)
824  {
825  $sendmailoption=ini_get('mail.force_extra_parameters');
826  if (empty($sendmailoption) || ! preg_match('/ba/',$sendmailoption))
827  {
828  print info_admin($langs->trans("SendmailOptionNotComplete"));
829  }
830  }*/
831  // Warning 2
832  print info_admin($langs->trans("SendmailOptionMayHurtBuggedMTA"));
833  }
834 
835  if (!in_array($action, array('testconnect', 'test', 'testhtml'))) {
836  $text = '';
837  if ($conf->global->MAIN_MAIL_SENDMODE == 'mail') {
838  //$text .= $langs->trans("WarningPHPMail"); // To encourage to use SMTPS
839  }
840 
841  if ($conf->global->MAIN_MAIL_SENDMODE == 'mail') {
842  if (!empty($conf->global->MAIN_EXTERNAL_MAIL_SPF_STRING_TO_ADD)) {
843  // List of string to add in SPF if the setup use the mail method. Example 'include:sendgrid.net include:spf.mydomain.com'
844  $text .= ($text ? '<br><br>' : '').'<!-- MAIN_EXTERNAL_MAIL_SPF_STRING_TO_ADD -->'.$langs->trans("WarningPHPMailSPF", $conf->global->MAIN_EXTERNAL_MAIL_SPF_STRING_TO_ADD);
845  } else {
846  // MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS is list of IPs where email is sent from. Example: '1.2.3.4, [aaaa:bbbb:cccc:dddd]'.
847  if (!empty($conf->global->MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS)) {
848  // List of IP show as record to add in SPF if we use the mail method
849  $text .= ($text ? '<br><br>' : '').'<!-- MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS -->'.$langs->trans("WarningPHPMailSPF", $conf->global->MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS);
850  }
851  }
852  } else {
853  if (!empty($conf->global->MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS)) {
854  // 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]'
855  // TODO Add a key to allow to show the IP/name of server detected dynamically
856  $text .= ($text ? '<br><br>' : '').'<!-- MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS -->'.$langs->trans("WarningPHPMail2", $conf->global->MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS);
857  }
858  if (!empty($conf->global->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.
859  // List of string to add in SPF if we use the smtp method. Example 'include:spf.mydomain.com'
860  $text .= ($text ? '<br><br>' : '').'<!-- MAIN_EXTERNAL_SMTP_SPF_STRING_TO_ADD -->'.$langs->trans("WarningPHPMailSPF", $conf->global->MAIN_EXTERNAL_SMTP_SPF_STRING_TO_ADD);
861  }
862  }
863  $companyemail = getDolGlobalString('MAIN_INFO_SOCIETE_MAIL');
864  $dnsinfo = false;
865  if (!empty($companyemail) && function_exists('dns_get_record')) {
866  $arrayofemailparts = explode('@', $companyemail);
867  if (count($arrayofemailparts) == 2) {
868  $domain = $arrayofemailparts[1];
869  $dnsinfo = dns_get_record($domain, DNS_TXT);
870  }
871  }
872  if (!empty($dnsinfo) && is_array($dnsinfo)) {
873  foreach ($dnsinfo as $info) {
874  if (strpos($info['txt'], 'v=spf') !== false) {
875  $text .= ($text ? '<br><br>' : '').$langs->trans("ActualMailSPFRecordFound", $companyemail, $info['txt']);
876  }
877  }
878  }
879  if ($text) {
880  print info_admin($text);
881  }
882  }
883 
884  // Run the test to connect
885  if ($action == 'testconnect') {
886  print '<div id="formmailaftertstconnect" name="formmailaftertstconnect"></div>';
887  print load_fiche_titre($langs->trans("DoTestServerAvailability"));
888 
889  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
890  $mail = new CMailFile('', '', '', '', array(), array(), array(), '', '', 0, '', '', '', '', $trackid, $sendcontext);
891  $result = $mail->check_server_port($server, $port);
892  if ($result) {
893  print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort", $server, $port).'</div>';
894  } else {
895  $errormsg = $langs->trans("ServerNotAvailableOnIPOrPort", $server, $port);
896 
897  if ($mail->error) {
898  $errormsg .= ' - '.$mail->error;
899  }
900 
901  setEventMessages($errormsg, null, 'errors');
902  }
903  print '<br>';
904  }
905 
906  // Show email send test form
907  if ($action == 'test' || $action == 'testhtml') {
908  print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
909  print load_fiche_titre($action == 'testhtml' ? $langs->trans("DoTestSendHTML") : $langs->trans("DoTestSend"));
910 
911  print dol_get_fiche_head('');
912 
913  // Cree l'objet formulaire mail
914  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
915  $formmail = new FormMail($db);
916  $formmail->trackid = (($action == 'testhtml') ? "testhtml" : "test");
917  $formmail->fromname = (GETPOSTISSET('fromname') ? GETPOST('fromname') : $conf->global->MAIN_MAIL_EMAIL_FROM);
918  $formmail->frommail = (GETPOSTISSET('frommail') ? GETPOST('frommail') : $conf->global->MAIN_MAIL_EMAIL_FROM);
919  $formmail->fromid = $user->id;
920  $formmail->fromalsorobot = 1;
921  $formmail->fromtype = (GETPOSTISSET('fromtype') ?GETPOST('fromtype', 'aZ09') : (!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE) ? $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE : 'user'));
922  $formmail->withfromreadonly = 1;
923  $formmail->withsubstit = 1;
924  $formmail->withfrom = 1;
925  $formmail->witherrorsto = 1;
926  $formmail->withto = (GETPOSTISSET('sendto') ? GETPOST('sendto', 'restricthtml') : ($user->email ? $user->email : 1));
927  $formmail->withtocc = (GETPOSTISSET('sendtocc') ? GETPOST('sendtocc', 'restricthtml') : 1); // ! empty to keep field if empty
928  $formmail->withtoccc = (GETPOSTISSET('sendtoccc') ? GETPOST('sendtoccc', 'restricthtml') : 1); // ! empty to keep field if empty
929  $formmail->withtopic = (GETPOSTISSET('subject') ? GETPOST('subject') : $langs->trans("Test"));
930  $formmail->withtopicreadonly = 0;
931  $formmail->withfile = 2;
932  $formmail->withbody = (GETPOSTISSET('message') ? GETPOST('message', 'restricthtml') : ($action == 'testhtml' ? $langs->transnoentities("PredefinedMailTestHtml") : $langs->transnoentities("PredefinedMailTest")));
933  $formmail->withbodyreadonly = 0;
934  $formmail->withcancel = 1;
935  $formmail->withdeliveryreceipt = 1;
936  $formmail->withfckeditor = ($action == 'testhtml' ? 1 : 0);
937  $formmail->ckeditortoolbar = 'dolibarr_mailings';
938  // Tableau des substitutions
939  $formmail->substit = $substitutionarrayfortest;
940  // Tableau des parametres complementaires du post
941  $formmail->param["action"] = "send";
942  $formmail->param["models"] = "body";
943  $formmail->param["mailid"] = 0;
944  $formmail->param["returnurl"] = $_SERVER["PHP_SELF"];
945 
946  // Init list of files
947  if (GETPOST("mode", "aZ09") == 'init') {
948  $formmail->clear_attached_files();
949  }
950 
951  print $formmail->get_form('addfile', 'removefile');
952 
953  print dol_get_fiche_end();
954 
955  // References
956  print '<span class="opacitymedium">'.$langs->trans("EMailsWillHaveMessageID").': ';
957  print dol_escape_htmltag('<timestamp.*@'.dol_getprefix('email').'>');
958  print '</span>';
959  }
960 }
961 
962 // End of page
963 llxFooter();
964 $db->close();
yn
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
Definition: functions.lib.php:6491
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
img_help
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
Definition: functions.lib.php:4481
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4521
CMailFile
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Definition: CMailFile.class.php:38
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
isValidEmail
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
Definition: functions.lib.php:3681
$wikihelp
if($actionsave) if(!isset($conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY)) $wikihelp
View.
Definition: agenda_xcal.php:72
dol_string_nohtmltag
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
Definition: functions.lib.php:6694
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
info_admin
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
Definition: functions.lib.php:4800
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
dolibarr_set_const
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:627
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
email_admin_prepare_head
email_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: admin.lib.php:1991
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
EmailSenderProfile
Class for EmailSenderProfile.
Definition: emailsenderprofile.class.php:37
FormMail
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
Definition: html.formmail.class.php:38
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:93
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
complete_substitutions_array
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...
Definition: functions.lib.php:7961