dolibarr  16.0.1
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="'.$mainsmtppw.'" 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="'.$mainsmtppw.'">';
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  print '<tr class="oddeven"><td class="fieldrequired">'.$langs->trans("MAIN_MAIL_EMAIL_FROM", ini_get('sendmail_from') ?ini_get('sendmail_from') : $langs->transnoentities("Undefined")).'</td>';
509  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 : '');
510  print '"></td></tr>';
511 
512  // Default from type
513  $liste = array();
514  $liste['user'] = $langs->trans('UserEmail');
515  $liste['company'] = $langs->trans('CompanyEmail').' ('.(empty($conf->global->MAIN_INFO_SOCIETE_MAIL) ? $langs->trans("NotDefined") : $conf->global->MAIN_INFO_SOCIETE_MAIL).')';
516 
517  print '<tr class="oddeven"><td>'.$langs->trans('MAIN_MAIL_DEFAULT_FROMTYPE').'</td><td>';
518  print $form->selectarray('MAIN_MAIL_DEFAULT_FROMTYPE', $liste, getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE'), 0);
519  print '</td></tr>';
520 
521  // From
522  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ERRORS_TO").'</td>';
523  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 : '');
524  print '"></td></tr>';
525 
526  // Autocopy to
527  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
528  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 : '');
529  print '"></td></tr>';
530 
531  // Add user to select destinaries list
532  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ENABLED_USER_DEST_SELECT").'</td><td>';
533  print $form->selectyesno('MAIN_MAIL_ENABLED_USER_DEST_SELECT', getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT'), 1);
534  print '</td></tr>';
535 
536  print '</table>';
537 
538  print dol_get_fiche_end();
539 
540  print $form->buttonsSaveCancel();
541 
542  print '</form>';
543 } else {
544  print dol_get_fiche_head($head, 'common', '', -1);
545 
546  print '<span class="opacitymedium">'.$langs->trans("EMailsDesc")."</span><br>\n";
547  print "<br><br>\n";
548 
549  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
550  print '<table class="noborder centpercent">';
551  print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
552 
553  // Disable
554  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_MAILS").'</td><td>'.yn(!empty($conf->global->MAIN_DISABLE_ALL_MAILS));
555  if (!empty($conf->global->MAIN_DISABLE_ALL_MAILS)) {
556  print img_warning($langs->trans("Disabled"));
557  }
558  print '</td></tr>';
559 
560  if (empty($conf->global->MAIN_DISABLE_ALL_MAILS)) {
561  // Force e-mail recipient
562  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_FORCE_SENDTO").'</td><td>'.getDolGlobalString('MAIN_MAIL_FORCE_SENDTO');
563  if (!empty(getDolGlobalString('MAIN_MAIL_FORCE_SENDTO'))) {
564  if (!isValidEmail(getDolGlobalString('MAIN_MAIL_FORCE_SENDTO'))) {
565  print img_warning($langs->trans("ErrorBadEMail"));
566  } else {
567  print img_warning($langs->trans("RecipientEmailsWillBeReplacedWithThisValue"));
568  }
569  }
570  print '</td></tr>';
571  }
572 
573  print '</table>';
574  print '</div>';
575 
576  if (empty($conf->global->MAIN_DISABLE_ALL_MAILS)) {
577  print '<br>';
578 
579  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
580  print '<table class="noborder centpercent">';
581  print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td></td></tr>';
582 
583  // Method
584  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
585  $text = $listofmethods[$conf->global->MAIN_MAIL_SENDMODE];
586  if (empty($text)) {
587  $text = $langs->trans("Undefined").img_warning();
588  }
589  print $text;
590 
591  if ($conf->global->MAIN_MAIL_SENDMODE == 'mail' && empty($conf->global->MAIN_HIDE_WARNING_TO_ENCOURAGE_SMTP_SETUP)) {
592  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');
593  }
594 
595  print '</td></tr>';
596 
597  // Host server
598  if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'mail')) {
599  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike").'</td><td><span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span></td></tr>';
600  } else {
601  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>';
602  }
603 
604  // Port
605  if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'mail')) {
606  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").'</td><td><span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span></td></tr>';
607  } else {
608  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>';
609  }
610 
611  // SMTPS ID
612  if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))) {
613  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>'.$conf->global->MAIN_MAIL_SMTPS_ID.'</td></tr>';
614  }
615 
616  // SMTPS PW
617  if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))) {
618  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>'.preg_replace('/./', '*', $conf->global->MAIN_MAIL_SMTPS_PW).'</td></tr>';
619  }
620 
621  // TLS
622  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
623  if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))) {
624  if (function_exists('openssl_open')) {
625  print yn($conf->global->MAIN_MAIL_EMAIL_TLS);
626  } else {
627  print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
628  }
629  } else {
630  print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
631  }
632  print '</td></tr>';
633 
634  // STARTTLS
635  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
636  if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))) {
637  if (function_exists('openssl_open')) {
638  print yn($conf->global->MAIN_MAIL_EMAIL_STARTTLS);
639  } else {
640  print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
641  }
642  } else {
643  print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
644  }
645  print '</td></tr>';
646 
647  // SMTP_ALLOW_SELF_SIGNED
648  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").'</td><td>';
649  if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))) {
650  if (function_exists('openssl_open')) {
651  print yn($conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED);
652  } else {
653  print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
654  }
655  } else {
656  print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
657  }
658  print '</td></tr>';
659 
660 
661  if ($conf->global->MAIN_MAIL_SENDMODE == 'swiftmailer') {
662  // DKIM
663  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_ENABLED").'</td><td>';
664  if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('swiftmailer'))) {
665  if (function_exists('openssl_open')) {
666  print yn(getDolGlobalInt('MAIN_MAIL_EMAIL_DKIM_ENABLED'));
667  } else {
668  print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
669  }
670  } else {
671  print yn(0).' ('.$langs->trans("NotSupported").')';
672  }
673  print '</td></tr>';
674 
675  // Domain
676  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_DOMAIN").'</td>';
677  print '<td>'.getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_DOMAIN');
678  print '</td></tr>';
679 
680  // Selector
681  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_SELECTOR").'</td>';
682  print '<td>'.getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_SELECTOR');
683  print '</td></tr>';
684 
685  // PRIVATE KEY
686  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").'</td>';
687  print '<td>'.getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY');
688  print '</td></tr>';
689  }
690 
691  print '</table>';
692  print '</div>';
693 
694  if ($conf->global->MAIN_MAIL_SENDMODE == 'mail' && empty($conf->global->MAIN_HIDE_WARNING_TO_ENCOURAGE_SMTP_SETUP)) {
695  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');
696  }
697 
698  print '<br>';
699 
700  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
701  print '<table class="noborder centpercent">';
702  print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("OtherOptions").'</td><td></td></tr>';
703 
704  // From
705  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_FROM", ini_get('sendmail_from') ?ini_get('sendmail_from') : $langs->transnoentities("Undefined")).'</td>';
706  print '<td>'.$conf->global->MAIN_MAIL_EMAIL_FROM;
707  if (empty($conf->global->MAIN_MAIL_EMAIL_FROM)) {
708  print img_warning($langs->trans("Mandatory"));
709  } elseif (!isValidEmail($conf->global->MAIN_MAIL_EMAIL_FROM)) {
710  print img_warning($langs->trans("ErrorBadEMail"));
711  }
712  print '</td></tr>';
713 
714  // Default from type
715  $liste = array();
716  $liste['user'] = $langs->trans('UserEmail');
717  $liste['company'] = $langs->trans('CompanyEmail').' ('.(empty($conf->global->MAIN_INFO_SOCIETE_MAIL) ? $langs->trans("NotDefined") : $conf->global->MAIN_INFO_SOCIETE_MAIL).')';
718  $sql = 'SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile';
719  $sql .= ' WHERE active = 1 AND (private = 0 OR private = '.((int) $user->id).')';
720  $resql = $db->query($sql);
721  if ($resql) {
722  $num = $db->num_rows($resql);
723  $i = 0;
724  while ($i < $num) {
725  $obj = $db->fetch_object($resql);
726  if ($obj) {
727  $liste['senderprofile_'.$obj->rowid] = $obj->label.' <'.$obj->email.'>';
728  }
729  $i++;
730  }
731  } else {
732  dol_print_error($db);
733  }
734 
735  print '<tr class="oddeven"><td>'.$langs->trans('MAIN_MAIL_DEFAULT_FROMTYPE').'</td>';
736  print '<td>';
737  if (getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE') === 'robot') {
738  print $langs->trans('RobotEmail');
739  } elseif (getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE') === 'user') {
740  print $langs->trans('UserEmail');
741  } elseif (getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE') === 'company') {
742  print $langs->trans('CompanyEmail').' '.dol_escape_htmltag('<'.$mysoc->email.'>');
743  } else {
744  $id = preg_replace('/senderprofile_/', '', getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE'));
745  if ($id > 0) {
746  include_once DOL_DOCUMENT_ROOT.'/core/class/emailsenderprofile.class.php';
747  $emailsenderprofile = new EmailSenderProfile($db);
748  $emailsenderprofile->fetch($id);
749  print $emailsenderprofile->label.' '.dol_escape_htmltag('<'.$emailsenderprofile->email.'>');
750  }
751  }
752  print '</td></tr>';
753 
754  // Errors To
755  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ERRORS_TO").'</td>';
756  print '<td>'.(getDolGlobalString('MAIN_MAIL_ERRORS_TO'));
757  if (!empty($conf->global->MAIN_MAIL_ERRORS_TO) && !isValidEmail($conf->global->MAIN_MAIL_ERRORS_TO)) {
758  print img_warning($langs->trans("ErrorBadEMail"));
759  }
760  print '</td></tr>';
761 
762  // Autocopy to
763  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
764  print '<td>';
765  if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) {
766  $listofemail = explode(',', $conf->global->MAIN_MAIL_AUTOCOPY_TO);
767  $i = 0;
768  foreach ($listofemail as $key => $val) {
769  if ($i) {
770  print ', ';
771  }
772  $val = trim($val);
773  print $val;
774  if (!isValidEmail($val, 0, 1)) {
775  print img_warning($langs->trans("ErrorBadEMail", $val));
776  }
777  $i++;
778  }
779  } else {
780  print '&nbsp;';
781  }
782  print '</td></tr>';
783 
784  //Add user to select destinaries list
785  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>';
786 
787  print '</table>';
788  print '</div>';
789  }
790 
791  print dol_get_fiche_end();
792 
793 
794  // Actions button
795  print '<div class="tabsAction">';
796 
797  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
798 
799  if (empty($conf->global->MAIN_DISABLE_ALL_MAILS)) {
800  if ($conf->global->MAIN_MAIL_SENDMODE != 'mail' || !$linuxlike) {
801  if (function_exists('fsockopen') && $port && $server) {
802  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect&date='.dol_now().'#formmailaftertstconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
803  }
804  } else {
805  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
806  }
807 
808  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&mode=init#formmailbeforetitle">'.$langs->trans("DoTestSend").'</a>';
809 
810  if (!empty($conf->fckeditor->enabled)) {
811  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testhtml&mode=init#formmailbeforetitle">'.$langs->trans("DoTestSendHTML").'</a>';
812  }
813  }
814 
815  print '</div>';
816 
817 
818  if ($conf->global->MAIN_MAIL_SENDMODE == 'mail' && empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)) {
819  /*
820  // Warning 1
821  if ($linuxlike)
822  {
823  $sendmailoption=ini_get('mail.force_extra_parameters');
824  if (empty($sendmailoption) || ! preg_match('/ba/',$sendmailoption))
825  {
826  print info_admin($langs->trans("SendmailOptionNotComplete"));
827  }
828  }*/
829  // Warning 2
830  print info_admin($langs->trans("SendmailOptionMayHurtBuggedMTA"));
831  }
832 
833  if (!in_array($action, array('testconnect', 'test', 'testhtml'))) {
834  $text = '';
835  if ($conf->global->MAIN_MAIL_SENDMODE == 'mail') {
836  //$text .= $langs->trans("WarningPHPMail"); // To encourage to use SMTPS
837  }
838 
839  if ($conf->global->MAIN_MAIL_SENDMODE == 'mail') {
840  if (!empty($conf->global->MAIN_EXTERNAL_MAIL_SPF_STRING_TO_ADD)) {
841  // List of string to add in SPF if the setup use the mail method. Example 'include:sendgrid.net include:spf.mydomain.com'
842  $text .= ($text ? '<br><br>' : '').'<!-- MAIN_EXTERNAL_MAIL_SPF_STRING_TO_ADD -->'.$langs->trans("WarningPHPMailSPF", $conf->global->MAIN_EXTERNAL_MAIL_SPF_STRING_TO_ADD);
843  } else {
844  // MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS is list of IPs where email is sent from. Example: '1.2.3.4, [aaaa:bbbb:cccc:dddd]'.
845  if (!empty($conf->global->MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS)) {
846  // List of IP show as record to add in SPF if we use the mail method
847  $text .= ($text ? '<br><br>' : '').'<!-- MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS -->'.$langs->trans("WarningPHPMailSPF", $conf->global->MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS);
848  }
849  }
850  } else {
851  if (!empty($conf->global->MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS)) {
852  // 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]'
853  // TODO Add a key to allow to show the IP/name of server detected dynamically
854  $text .= ($text ? '<br><br>' : '').'<!-- MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS -->'.$langs->trans("WarningPHPMail2", $conf->global->MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS);
855  }
856  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.
857  // List of string to add in SPF if we use the smtp method. Example 'include:spf.mydomain.com'
858  $text .= ($text ? '<br><br>' : '').'<!-- MAIN_EXTERNAL_SMTP_SPF_STRING_TO_ADD -->'.$langs->trans("WarningPHPMailSPF", $conf->global->MAIN_EXTERNAL_SMTP_SPF_STRING_TO_ADD);
859  }
860  }
861  $companyemail = getDolGlobalString('MAIN_INFO_SOCIETE_MAIL');
862  $dnsinfo = false;
863  if (!empty($companyemail) && function_exists('dns_get_record')) {
864  $arrayofemailparts = explode('@', $companyemail);
865  if (count($arrayofemailparts) == 2) {
866  $domain = $arrayofemailparts[1];
867  $dnsinfo = dns_get_record($domain, DNS_TXT);
868  }
869  }
870  if (!empty($dnsinfo) && is_array($dnsinfo)) {
871  foreach ($dnsinfo as $info) {
872  if (strpos($info['txt'], 'v=spf') !== false) {
873  $text .= ($text ? '<br><br>' : '').$langs->trans("ActualMailSPFRecordFound", $companyemail, $info['txt']);
874  }
875  }
876  }
877  if ($text) {
878  print info_admin($text);
879  }
880  }
881 
882  // Run the test to connect
883  if ($action == 'testconnect') {
884  print '<div id="formmailaftertstconnect" name="formmailaftertstconnect"></div>';
885  print load_fiche_titre($langs->trans("DoTestServerAvailability"));
886 
887  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
888  $mail = new CMailFile('', '', '', '', array(), array(), array(), '', '', 0, '', '', '', '', $trackid, $sendcontext);
889  $result = $mail->check_server_port($server, $port);
890  if ($result) {
891  print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort", $server, $port).'</div>';
892  } else {
893  $errormsg = $langs->trans("ServerNotAvailableOnIPOrPort", $server, $port);
894 
895  if ($mail->error) {
896  $errormsg .= ' - '.$mail->error;
897  }
898 
899  setEventMessages($errormsg, null, 'errors');
900  }
901  print '<br>';
902  }
903 
904  // Show email send test form
905  if ($action == 'test' || $action == 'testhtml') {
906  print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
907  print load_fiche_titre($action == 'testhtml' ? $langs->trans("DoTestSendHTML") : $langs->trans("DoTestSend"));
908 
909  print dol_get_fiche_head('');
910 
911  // Cree l'objet formulaire mail
912  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
913  $formmail = new FormMail($db);
914  $formmail->trackid = (($action == 'testhtml') ? "testhtml" : "test");
915  $formmail->fromname = (GETPOSTISSET('fromname') ? GETPOST('fromname') : $conf->global->MAIN_MAIL_EMAIL_FROM);
916  $formmail->frommail = (GETPOSTISSET('frommail') ? GETPOST('frommail') : $conf->global->MAIN_MAIL_EMAIL_FROM);
917  $formmail->fromid = $user->id;
918  $formmail->fromalsorobot = 1;
919  $formmail->fromtype = (GETPOSTISSET('fromtype') ?GETPOST('fromtype', 'aZ09') : (!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE) ? $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE : 'user'));
920  $formmail->withfromreadonly = 1;
921  $formmail->withsubstit = 1;
922  $formmail->withfrom = 1;
923  $formmail->witherrorsto = 1;
924  $formmail->withto = (GETPOSTISSET('sendto') ? GETPOST('sendto', 'restricthtml') : ($user->email ? $user->email : 1));
925  $formmail->withtocc = (GETPOSTISSET('sendtocc') ? GETPOST('sendtocc', 'restricthtml') : 1); // ! empty to keep field if empty
926  $formmail->withtoccc = (GETPOSTISSET('sendtoccc') ? GETPOST('sendtoccc', 'restricthtml') : 1); // ! empty to keep field if empty
927  $formmail->withtopic = (GETPOSTISSET('subject') ? GETPOST('subject') : $langs->trans("Test"));
928  $formmail->withtopicreadonly = 0;
929  $formmail->withfile = 2;
930  $formmail->withbody = (GETPOSTISSET('message') ? GETPOST('message', 'restricthtml') : ($action == 'testhtml' ? $langs->transnoentities("PredefinedMailTestHtml") : $langs->transnoentities("PredefinedMailTest")));
931  $formmail->withbodyreadonly = 0;
932  $formmail->withcancel = 1;
933  $formmail->withdeliveryreceipt = 1;
934  $formmail->withfckeditor = ($action == 'testhtml' ? 1 : 0);
935  $formmail->ckeditortoolbar = 'dolibarr_mailings';
936  // Tableau des substitutions
937  $formmail->substit = $substitutionarrayfortest;
938  // Tableau des parametres complementaires du post
939  $formmail->param["action"] = "send";
940  $formmail->param["models"] = "body";
941  $formmail->param["mailid"] = 0;
942  $formmail->param["returnurl"] = $_SERVER["PHP_SELF"];
943 
944  // Init list of files
945  if (GETPOST("mode", "aZ09") == 'init') {
946  $formmail->clear_attached_files();
947  }
948 
949  print $formmail->get_form('addfile', 'removefile');
950 
951  print dol_get_fiche_end();
952 
953  // References
954  print '<span class="opacitymedium">'.$langs->trans("EMailsWillHaveMessageID").': ';
955  print dol_escape_htmltag('<timestamp.*@'.dol_getprefix('email').'>');
956  print '</span>';
957  }
958 }
959 
960 // End of page
961 llxFooter();
962 $db->close();
if($actionsave) if(!isset($conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY)) $wikihelp
View.
Definition: agenda_xcal.php:72
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Classe permettant la generation du formulaire html d&#39;envoi de mail unitaire Usage: $formail = new For...
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
email_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: admin.lib.php:1991
dol_now($mode= 'auto')
Return date for now.
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
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default= '')
Return dolibarr global constant string value.
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
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...
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form...
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= 'hideonsmartphone', $textfordropdown= '')
Show information for admin users or standard users.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext,$replyto); $mailfile-&gt;sendfile();.
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 ...
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
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class for EmailSenderProfile.
llxFooter()
Empty footer.
Definition: wrapper.php:73
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 &quot;subst...