dolibarr  9.0.0
mails.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2012 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 <http://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','alpha');
34 
35 if (! $user->admin) accessforbidden();
36 
37 $usersignature=$user->signature;
38 // For action = test or send, we ensure that content is not html, even for signature, because this we want a test with NO html.
39 if ($action == 'test' || $action == 'send')
40 {
41  $usersignature=dol_string_nohtmltag($usersignature);
42 }
43 
44 $substitutionarrayfortest=array(
45 '__DOL_MAIN_URL_ROOT__'=>DOL_MAIN_URL_ROOT,
46 '__ID__' => 'RecipientIdRecord',
47 //'__EMAIL__' => 'RecipientEMail', // Done into actions_sendmails
48 '__CHECK_READ__' => (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"/>':'',
49 '__USER_SIGNATURE__' => (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))?$usersignature:''), // Done into actions_sendmails
50 '__LOGIN__' => 'RecipientLogin',
51 '__LASTNAME__' => 'RecipientLastname',
52 '__FIRSTNAME__' => 'RecipientFirstname',
53 '__ADDRESS__'=> 'RecipientAddress',
54 '__ZIP__'=> 'RecipientZip',
55 '__TOWN_'=> 'RecipientTown',
56 '__COUNTRY__'=> 'RecipientCountry'
57 );
58 complete_substitutions_array($substitutionarrayfortest, $langs);
59 
60 
61 
62 /*
63  * Actions
64  */
65 
66 if ($action == 'update' && empty($_POST["cancel"]))
67 {
68  dolibarr_set_const($db, "MAIN_DISABLE_ALL_MAILS", GETPOST("MAIN_DISABLE_ALL_MAILS"), 'chaine', 0, '', $conf->entity);
69  dolibarr_set_const($db, "MAIN_MAIL_FORCE_SENDTO", GETPOST("MAIN_MAIL_FORCE_SENDTO"), 'chaine', 0, '', $conf->entity);
70  dolibarr_set_const($db, "MAIN_MAIL_ENABLED_USER_DEST_SELECT", GETPOST("MAIN_MAIL_ENABLED_USER_DEST_SELECT"), 'chaine', 0, '', $conf->entity);
71  // Send mode parameters
72  dolibarr_set_const($db, "MAIN_MAIL_SENDMODE", GETPOST("MAIN_MAIL_SENDMODE"), 'chaine', 0, '', $conf->entity);
73  dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT", GETPOST("MAIN_MAIL_SMTP_PORT"), 'chaine', 0, '', $conf->entity);
74  dolibarr_set_const($db, "MAIN_MAIL_SMTP_SERVER", GETPOST("MAIN_MAIL_SMTP_SERVER"), 'chaine', 0, '', $conf->entity);
75  dolibarr_set_const($db, "MAIN_MAIL_SMTPS_ID", GETPOST("MAIN_MAIL_SMTPS_ID"), 'chaine', 0, '', $conf->entity);
76  dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW", GETPOST("MAIN_MAIL_SMTPS_PW"), 'chaine', 0, '', $conf->entity);
77  dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS", GETPOST("MAIN_MAIL_EMAIL_TLS"), 'chaine', 0, '', $conf->entity);
78  dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS", GETPOST("MAIN_MAIL_EMAIL_STARTTLS"), 'chaine', 0, '', $conf->entity);
79 
80  dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_ENABLED", GETPOST("MAIN_MAIL_EMAIL_DKIM_ENABLED"), 'chaine', 0, '', $conf->entity);
81  dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_DOMAIN", GETPOST("MAIN_MAIL_EMAIL_DKIM_DOMAIN"), 'chaine', 0, '', $conf->entity);
82  dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_SELECTOR", GETPOST("MAIN_MAIL_EMAIL_DKIM_SELECTOR"), 'chaine', 0, '', $conf->entity);
83  dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY", GETPOST("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY"), 'chaine', 0, '', $conf->entity);
84  // Content parameters
85  dolibarr_set_const($db, "MAIN_MAIL_EMAIL_FROM", GETPOST("MAIN_MAIL_EMAIL_FROM"), 'chaine', 0, '', $conf->entity);
86  dolibarr_set_const($db, "MAIN_MAIL_ERRORS_TO", GETPOST("MAIN_MAIL_ERRORS_TO"), 'chaine', 0, '', $conf->entity);
87  dolibarr_set_const($db, "MAIN_MAIL_AUTOCOPY_TO", GETPOST("MAIN_MAIL_AUTOCOPY_TO"),'chaine', 0, '', $conf->entity);
88  dolibarr_set_const($db, 'MAIN_MAIL_DEFAULT_FROMTYPE', GETPOST('MAIN_MAIL_DEFAULT_FROMTYPE'), 'chaine', 0, '', $conf->entity);
89 
90  header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
91  exit;
92 }
93 
94 
95 // Actions to send emails
96 $id=0;
97 $actiontypecode=''; // Not an event for agenda
98 $trigger_name=''; // Disable triggers
99 $paramname='id';
100 $mode='emailfortest';
101 $trackid=(($action == 'testhtml')?"testhtml":"test");
102 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
103 
104 if ($action == 'presend' && GETPOST('trackid') == 'test') $action='test';
105 if ($action == 'presend' && GETPOST('trackid') == 'testhtml') $action='testhtml';
106 
107 
108 
109 
110 /*
111  * View
112  */
113 
114 $linuxlike=1;
115 if (preg_match('/^win/i',PHP_OS)) $linuxlike=0;
116 if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0;
117 
118 if (empty($conf->global->MAIN_MAIL_SENDMODE)) $conf->global->MAIN_MAIL_SENDMODE='mail';
119 $port=! empty($conf->global->MAIN_MAIL_SMTP_PORT)?$conf->global->MAIN_MAIL_SMTP_PORT:ini_get('smtp_port');
120 if (! $port) $port=25;
121 $server=! empty($conf->global->MAIN_MAIL_SMTP_SERVER)?$conf->global->MAIN_MAIL_SMTP_SERVER:ini_get('SMTP');
122 if (! $server) $server='127.0.0.1';
123 
124 
125 $wikihelp='EN:Setup_EMails|FR:Paramétrage_EMails|ES:Configuración_EMails';
126 llxHeader('',$langs->trans("Setup"),$wikihelp);
127 
128 print load_fiche_titre($langs->trans("EMailsSetup"),'','title_setup');
129 
130 $head = email_admin_prepare_head();
131 
132 // List of sending methods
133 $listofmethods=array();
134 $listofmethods['mail']='PHP mail function';
135 //$listofmethods['simplemail']='Simplemail class';
136 $listofmethods['smtps']='SMTP/SMTPS socket library';
137 $listofmethods['swiftmailer']='Swift Mailer socket library';
138 
139 
140 if ($action == 'edit')
141 {
142  $form=new Form($db);
143 
144  if ($conf->use_javascript_ajax)
145  {
146  print "\n".'<script type="text/javascript" language="javascript">';
147  print 'jQuery(document).ready(function () {
148  function initfields()
149  {
150  if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'mail\')
151  {
152  console.log("I choose php mail mode");
153  jQuery(".drag").hide();
154  jQuery("#MAIN_MAIL_EMAIL_TLS").val(0);
155  jQuery("#MAIN_MAIL_EMAIL_TLS").prop("disabled", true);
156  jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val(0);
157  jQuery("#MAIN_MAIL_EMAIL_STARTTLS").prop("disabled", true);
158  jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val(0);
159  jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").prop("disabled", true);
160  jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").prop("disabled", true);
161  jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").prop("disabled", true);
162  jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").prop("disabled", true);
163  jQuery(".dkim").hide();
164  ';
165  if ($linuxlike)
166  {
167  print '
168  jQuery("#MAIN_MAIL_SMTP_SERVER").hide();
169  jQuery("#MAIN_MAIL_SMTP_PORT").hide();
170  jQuery("#smtp_server_mess").show();
171  jQuery("#smtp_port_mess").show();';
172  }
173  else
174  {
175  print '
176  jQuery("#MAIN_MAIL_SMTP_SERVER").prop("disabled", true);
177  jQuery("#MAIN_MAIL_SMTP_PORT").prop("disabled", true);
178  jQuery("#smtp_server_mess").hide();
179  jQuery("#smtp_port_mess").hide();';
180  }
181  print '
182  }
183  if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'smtps\')
184  {
185  console.log("I choose smtps mode");
186  jQuery(".drag").show();
187  jQuery("#MAIN_MAIL_EMAIL_TLS").val('.$conf->global->MAIN_MAIL_EMAIL_TLS.');
188  jQuery("#MAIN_MAIL_EMAIL_TLS").removeAttr("disabled");
189  jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS.');
190  jQuery("#MAIN_MAIL_EMAIL_STARTTLS").removeAttr("disabled");
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("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").hide();
197  jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").hide();
198  jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").hide();
199  jQuery("#MAIN_MAIL_SMTP_SERVER").removeAttr("disabled");
200  jQuery("#MAIN_MAIL_SMTP_PORT").removeAttr("disabled");
201  jQuery("#MAIN_MAIL_SMTP_SERVER").show();
202  jQuery("#MAIN_MAIL_SMTP_PORT").show();
203  jQuery("#smtp_server_mess").hide();
204  jQuery("#smtp_port_mess").hide();
205  jQuery(".dkim").hide();
206  }
207  if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'swiftmailer\')
208  {
209  console.log("I choose swiftmailer mode");
210  jQuery(".drag").show();
211  jQuery("#MAIN_MAIL_EMAIL_TLS").val('.$conf->global->MAIN_MAIL_EMAIL_TLS.');
212  jQuery("#MAIN_MAIL_EMAIL_TLS").removeAttr("disabled");
213  jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS.');
214  jQuery("#MAIN_MAIL_EMAIL_STARTTLS").removeAttr("disabled");
215  jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val('.$conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED.');
216  jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").removeAttr("disabled");
217  jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").removeAttr("disabled");
218  jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").removeAttr("disabled");
219  jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").removeAttr("disabled");
220  jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").show();
221  jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").show();
222  jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").show();
223  jQuery("#MAIN_MAIL_SMTP_SERVER").removeAttr("disabled");
224  jQuery("#MAIN_MAIL_SMTP_PORT").removeAttr("disabled");
225  jQuery("#MAIN_MAIL_SMTP_SERVER").show();
226  jQuery("#MAIN_MAIL_SMTP_PORT").show();
227  jQuery("#smtp_server_mess").hide();
228  jQuery("#smtp_port_mess").hide();
229  jQuery(".dkim").show();
230  }
231  }
232  initfields();
233  jQuery("#MAIN_MAIL_SENDMODE").change(function() {
234  initfields();
235  });
236  jQuery("#MAIN_MAIL_EMAIL_TLS").change(function() {
237  if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val() == 1)
238  jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val(0);
239  });
240  jQuery("#MAIN_MAIL_EMAIL_STARTTLS").change(function() {
241  if (jQuery("#MAIN_MAIL_EMAIL_TLS").val() == 1)
242  jQuery("#MAIN_MAIL_EMAIL_TLS").val(0);
243  });
244  })';
245  print '</script>'."\n";
246  }
247 
248  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
249  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
250  print '<input type="hidden" name="action" value="update">';
251 
252  dol_fiche_head($head, 'common', '', -1);
253 
254  print $langs->trans("EMailsDesc")."<br>\n";
255  print "<br>\n";
256 
257 
258  clearstatcache();
259 
260  print '<table class="noborder" width="100%">';
261  print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
262 
263  // Disable
264  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_MAILS").'</td><td>';
265  print $form->selectyesno('MAIN_DISABLE_ALL_MAILS',$conf->global->MAIN_DISABLE_ALL_MAILS,1);
266  print '</td></tr>';
267 
268  // Force e-mail recipient
269  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_FORCE_SENDTO").'</td><td>';
270  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:'') . '" />';
271  print '</td></tr>';
272 
273 
274  //Add user to select destinaries list
275  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ENABLED_USER_DEST_SELECT").'</td><td>';
276  print $form->selectyesno('MAIN_MAIL_ENABLED_USER_DEST_SELECT',$conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT,1);
277  print '</td></tr>';
278 
279  // Separator
280  print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
281 
282  // Method
283  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
284 
285  // SuperAdministrator access only
286  if ((empty($conf->global->MAIN_MODULE_MULTICOMPANY)) || ($user->admin && !$user->entity))
287  {
288  print $form->selectarray('MAIN_MAIL_SENDMODE',$listofmethods,$conf->global->MAIN_MAIL_SENDMODE);
289  }
290  else
291  {
292  $text = $listofmethods[$conf->global->MAIN_MAIL_SENDMODE];
293  if (empty($text)) $text = $langs->trans("Undefined");
294  $htmltext = $langs->trans("ContactSuperAdminForChange");
295  print $form->textwithpicto($text,$htmltext,1,'superadmin');
296  print '<input type="hidden" name="MAIN_MAIL_SENDMODE" value="'.$conf->global->MAIN_MAIL_SENDMODE.'">';
297  }
298  print '</td></tr>';
299 
300  // Host server
301  print '<tr class="oddeven"><td>';
302  if (! $conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE == 'mail')
303  {
304  print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
305  print '</td><td>';
306  print '<span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
307  }
308  else
309  {
310  $mainserver = (! empty($conf->global->MAIN_MAIL_SMTP_SERVER)?$conf->global->MAIN_MAIL_SMTP_SERVER:'');
311  $smtpserver = ini_get('SMTP')?ini_get('SMTP'):$langs->transnoentities("Undefined");
312  if ($linuxlike) print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
313  else print $langs->trans("MAIN_MAIL_SMTP_SERVER",$smtpserver);
314  print '</td><td>';
315  // SuperAdministrator access only
316  if (empty($conf->multicompany->enabled) || ($user->admin && ! $user->entity))
317  {
318  print '<input class="flat" id="MAIN_MAIL_SMTP_SERVER" name="MAIN_MAIL_SMTP_SERVER" size="18" value="' . $mainserver . '">';
319  print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_sav" name="MAIN_MAIL_SMTP_SERVER_sav" value="' . $mainserver . '">';
320  print '<span id="smtp_server_mess" class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
321  }
322  else
323  {
324  $text = ! empty($mainserver) ? $mainserver : $smtpserver;
325  $htmltext = $langs->trans("ContactSuperAdminForChange");
326  print $form->textwithpicto($text,$htmltext,1,'superadmin');
327  print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER" name="MAIN_MAIL_SMTP_SERVER" value="'.$mainserver.'">';
328  }
329  }
330  print '</td></tr>';
331 
332  // Port
333  print '<tr class="oddeven"><td>';
334  if (! $conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE == 'mail')
335  {
336  print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
337  print '</td><td>';
338  print '<span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
339  }
340  else
341  {
342  $mainport = (! empty($conf->global->MAIN_MAIL_SMTP_PORT) ? $conf->global->MAIN_MAIL_SMTP_PORT : '');
343  $smtpport = ini_get('smtp_port')?ini_get('smtp_port'):$langs->transnoentities("Undefined");
344  if ($linuxlike) print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
345  else print $langs->trans("MAIN_MAIL_SMTP_PORT",$smtpport);
346  print '</td><td>';
347  // SuperAdministrator access only
348  if (empty($conf->multicompany->enabled) || ($user->admin && ! $user->entity))
349  {
350  print '<input class="flat" id="MAIN_MAIL_SMTP_PORT" name="MAIN_MAIL_SMTP_PORT" size="3" value="' . $mainport . '">';
351  print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_sav" name="MAIN_MAIL_SMTP_PORT_sav" value="' . $mainport . '">';
352  print '<span id="smtp_port_mess" class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
353  }
354  else
355  {
356  $text = (! empty($mainport) ? $mainport : $smtpport);
357  $htmltext = $langs->trans("ContactSuperAdminForChange");
358  print $form->textwithpicto($text,$htmltext,1,'superadmin');
359  print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT" name="MAIN_MAIL_SMTP_PORT" value="'.$mainport.'">';
360  }
361  }
362  print '</td></tr>';
363 
364  // ID
365  if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))))
366  {
367 
368  $mainstmpid=(! empty($conf->global->MAIN_MAIL_SMTPS_ID)?$conf->global->MAIN_MAIL_SMTPS_ID:'');
369  print '<tr class="drag drop oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>';
370  // SuperAdministrator access only
371  if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity))
372  {
373  print '<input class="flat" name="MAIN_MAIL_SMTPS_ID" size="32" value="' . $mainstmpid . '">';
374  }
375  else
376  {
377  $htmltext = $langs->trans("ContactSuperAdminForChange");
378  print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_ID,$htmltext,1,'superadmin');
379  print '<input type="hidden" name="MAIN_MAIL_SMTPS_ID" value="'.$mainstmpid.'">';
380  }
381  print '</td></tr>';
382  }
383 
384  // PW
385  if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))))
386  {
387 
388  $mainsmtppw=(! empty($conf->global->MAIN_MAIL_SMTPS_PW)?$conf->global->MAIN_MAIL_SMTPS_PW:'');
389  print '<tr class="drag drop oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>';
390  // SuperAdministrator access only
391  if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity))
392  {
393  print '<input class="flat" type="password" name="MAIN_MAIL_SMTPS_PW" size="32" value="' . $mainsmtppw . '">';
394  }
395  else
396  {
397  $htmltext = $langs->trans("ContactSuperAdminForChange");
398  print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_PW,$htmltext,1,'superadmin');
399  print '<input type="hidden" name="MAIN_MAIL_SMTPS_PW" value="'.$mainsmtppw.'">';
400  }
401  print '</td></tr>';
402  }
403 
404  // TLS
405  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
406  if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))))
407  {
408  if (function_exists('openssl_open'))
409  {
410  print $form->selectyesno('MAIN_MAIL_EMAIL_TLS',(! empty($conf->global->MAIN_MAIL_EMAIL_TLS)?$conf->global->MAIN_MAIL_EMAIL_TLS:0),1);
411  }
412  else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
413  }
414  else print yn(0).' ('.$langs->trans("NotSupported").')';
415  print '</td></tr>';
416 
417  // STARTTLS
418  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
419  if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))))
420  {
421  if (function_exists('openssl_open'))
422  {
423  print $form->selectyesno('MAIN_MAIL_EMAIL_STARTTLS',(! empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS)?$conf->global->MAIN_MAIL_EMAIL_STARTTLS:0),1);
424  }
425  else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
426  }
427  else print yn(0).' ('.$langs->trans("NotSupported").')';
428  print '</td></tr>';
429 
430  // DKIM
431  print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_ENABLED").'</td><td>';
432  if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('swiftmailer'))))
433  {
434  if (function_exists('openssl_open'))
435  {
436  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);
437  }
438  else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
439  }
440  else print yn(0).' ('.$langs->trans("NotSupported").')';
441  print '</td></tr>';
442 
443  // DKIM Domain
444  print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_DOMAIN").'</td>';
445  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:'');
446  print '"></td></tr>';
447 
448  // DKIM Selector
449  print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_SELECTOR").'</td>';
450  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:'');
451  print '"></td></tr>';
452 
453  // DKIM PRIVATE KEY
454  print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").'</td>';
455  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>';
456  print '</td></tr>';
457 
458  // Separator
459  print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
460 
461  // From
462  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_FROM",ini_get('sendmail_from')?ini_get('sendmail_from'):$langs->transnoentities("Undefined")).'</td>';
463  print '<td><input class="flat" name="MAIN_MAIL_EMAIL_FROM" size="32" value="' . (! empty($conf->global->MAIN_MAIL_EMAIL_FROM)?$conf->global->MAIN_MAIL_EMAIL_FROM:'');
464  print '"></td></tr>';
465 
466  // Default from type
467  $liste = array();
468  $liste['user'] = $langs->trans('UserEmail');
469  $liste['company'] = $langs->trans('CompanyEmail').' ('.(empty($conf->global->MAIN_INFO_SOCIETE_MAIL)?$langs->trans("NotDefined"):$conf->global->MAIN_INFO_SOCIETE_MAIL).')';
470  /*
471  $sql='SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile WHERE active = 1';
472  $resql = $db->query($sql);
473  if ($resql)
474  {
475  $num = $db->num_rows($resql);
476  $i=0;
477  while($i < $num)
478  {
479  $obj = $db->fetch_object($resql);
480  if ($obj)
481  {
482  $liste['senderprofile_'.$obj->rowid] = $obj->label.' <'.$obj->email.'>';
483  }
484  $i++;
485  }
486  }
487  else dol_print_error($db);*/
488 
489  print '<tr class="oddeven"><td>'.$langs->trans('MAIN_MAIL_DEFAULT_FROMTYPE').'</td><td>';
490  print $form->selectarray('MAIN_MAIL_DEFAULT_FROMTYPE', $liste, $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE, 0);
491  print '</td></tr>';
492 
493  // Separator
494  print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
495 
496  // From
497  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ERRORS_TO").'</td>';
498  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:'');
499  print '"></td></tr>';
500 
501  // Autocopy to
502  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
503  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:'');
504  print '"></td></tr>';
505 
506  print '</table>';
507 
508  dol_fiche_end();
509 
510  print '<br><div class="center">';
511  print '<input class="button" type="submit" name="save" value="'.$langs->trans("Save").'">';
512  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
513  print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
514  print '</div>';
515 
516  print '</form>';
517 }
518 else
519 {
520  dol_fiche_head($head, 'common', '', -1);
521 
522  print $langs->trans("EMailsDesc")."<br>\n";
523  print "<br>\n";
524 
525  print '<table class="noborder" width="100%">';
526  print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
527 
528  // Disable
529  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_MAILS").'</td><td>'.yn($conf->global->MAIN_DISABLE_ALL_MAILS).'</td></tr>';
530 
531  // Force e-mail recipient
532  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_FORCE_SENDTO").'</td><td>'.$conf->global->MAIN_MAIL_FORCE_SENDTO;
533  if (! empty($conf->global->MAIN_MAIL_FORCE_SENDTO) && ! isValidEmail($conf->global->MAIN_MAIL_FORCE_SENDTO)) print img_warning($langs->trans("ErrorBadEMail"));
534  print '</td></tr>';
535 
536  //Add user to select destinaries list
537  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ENABLED_USER_DEST_SELECT").'</td><td>'.yn($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT).'</td></tr>';
538 
539  // Separator
540  print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
541 
542  // Method
543  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
544  $text=$listofmethods[$conf->global->MAIN_MAIL_SENDMODE];
545  if (empty($text)) $text=$langs->trans("Undefined").img_warning();
546  print $text;
547  print '</td></tr>';
548 
549  // Host server
550  if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'mail'))
551  {
552  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike").'</td><td><span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span></td></tr>';
553  }
554  else
555  {
556  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>';
557  }
558 
559  // Port
560  if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'mail'))
561  {
562  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").'</td><td><span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span></td></tr>';
563  }
564  else
565  {
566  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>';
567  }
568 
569  // SMTPS ID
570  if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))
571  {
572  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>'.$conf->global->MAIN_MAIL_SMTPS_ID.'</td></tr>';
573  }
574 
575  // SMTPS PW
576  if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))
577  {
578  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>'.preg_replace('/./','*',$conf->global->MAIN_MAIL_SMTPS_PW).'</td></tr>';
579  }
580 
581  // TLS
582  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
583  if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))
584  {
585  if (function_exists('openssl_open'))
586  {
587  print yn($conf->global->MAIN_MAIL_EMAIL_TLS);
588  }
589  else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
590  }
591  else print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
592  print '</td></tr>';
593 
594  // STARTTLS
595  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
596  if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))
597  {
598  if (function_exists('openssl_open'))
599  {
600  print yn($conf->global->MAIN_MAIL_EMAIL_STARTTLS);
601  }
602  else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
603  }
604  else print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
605  print '</td></tr>';
606 
607 
608  if ($conf->global->MAIN_MAIL_SENDMODE == 'swiftmailer')
609  {
610  // DKIM
611  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_ENABLED").'</td><td>';
612  if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('swiftmailer')))
613  {
614  if (function_exists('openssl_open'))
615  {
616  print yn($conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED);
617  }
618  else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
619  }
620  else print yn(0).' ('.$langs->trans("NotSupported").')';
621  print '</td></tr>';
622 
623  // Domain
624  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_DOMAIN").'</td>';
625  print '<td>' . $conf->global->MAIN_MAIL_EMAIL_DKIM_DOMAIN;
626  print '</td></tr>';
627 
628  // Selector
629  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_SELECTOR").'</td>';
630  print '<td>' . $conf->global->MAIN_MAIL_EMAIL_DKIM_SELECTOR;
631  print '</td></tr>';
632 
633  // PRIVATE KEY
634  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").'</td>';
635  print '<td>' . $conf->global->MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY;
636  print '</td></tr>';
637  }
638 
639  // Separator
640  print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
641 
642  // From
643  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_FROM",ini_get('sendmail_from')?ini_get('sendmail_from'):$langs->transnoentities("Undefined")).'</td>';
644  print '<td>'.$conf->global->MAIN_MAIL_EMAIL_FROM;
645  if (! empty($conf->global->MAIN_MAIL_EMAIL_FROM) && ! isValidEmail($conf->global->MAIN_MAIL_EMAIL_FROM)) print img_warning($langs->trans("ErrorBadEMail"));
646  print '</td></tr>';
647 
648  // Default from type
649  $liste = array();
650  $liste['user'] = $langs->trans('UserEmail');
651  $liste['company'] = $langs->trans('CompanyEmail').' ('.(empty($conf->global->MAIN_INFO_SOCIETE_MAIL)?$langs->trans("NotDefined"):$conf->global->MAIN_INFO_SOCIETE_MAIL).')';
652  $sql='SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile WHERE active = 1';
653  $resql = $db->query($sql);
654  if ($resql)
655  {
656  $num = $db->num_rows($resql);
657  $i=0;
658  while($i < $num)
659  {
660  $obj = $db->fetch_object($resql);
661  if ($obj)
662  {
663  $liste['senderprofile_'.$obj->rowid] = $obj->label.' <'.$obj->email.'>';
664  }
665  $i++;
666  }
667  }
668  else dol_print_error($db);
669 
670  print '<tr class="oddeven"><td>'.$langs->trans('MAIN_MAIL_DEFAULT_FROMTYPE').'</td>';
671  print '<td>';
672  if ($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE === 'robot')
673  {
674  print $langs->trans('RobotEmail');
675  }
676  else if ($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE === 'user')
677  {
678  print $langs->trans('UserEmail');
679  }
680  else if ($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE === 'company')
681  {
682  print $langs->trans('CompanyEmail').' '.dol_escape_htmltag('<'.$mysoc->email.'>');
683  }
684  else {
685  $id = preg_replace('/senderprofile_/', '', $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE);
686  if ($id > 0)
687  {
688  include_once DOL_DOCUMENT_ROOT.'/core/class/emailsenderprofile.class.php';
689  $emailsenderprofile = new EmailSenderProfile($db);
690  $emailsenderprofile->fetch($id);
691  print $emailsenderprofile->label.' '.dol_escape_htmltag('<'.$emailsenderprofile->email.'>');
692  }
693  }
694  print '</td></tr>';
695 
696  // Separator
697  print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
698 
699  // Errors To
700  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ERRORS_TO").'</td>';
701  print '<td>'.$conf->global->MAIN_MAIL_ERRORS_TO;
702  if (! empty($conf->global->MAIN_MAIL_ERRORS_TO) && ! isValidEmail($conf->global->MAIN_MAIL_ERRORS_TO)) print img_warning($langs->trans("ErrorBadEMail"));
703  print '</td></tr>';
704 
705  // Autocopy to
706  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
707  print '<td>';
708  if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_TO))
709  {
710  print $conf->global->MAIN_MAIL_AUTOCOPY_TO;
711  if (! isValidEmail($conf->global->MAIN_MAIL_AUTOCOPY_TO)) print img_warning($langs->trans("ErrorBadEMail"));
712  }
713  else
714  {
715  print '&nbsp;';
716  }
717  print '</td></tr>';
718 
719  print '</table>';
720 
721  dol_fiche_end();
722 
723 
724  // Actions button
725  print '<div class="tabsAction">';
726 
727  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
728 
729  if ($conf->global->MAIN_MAIL_SENDMODE != 'mail' || ! $linuxlike)
730  {
731  if (function_exists('fsockopen') && $port && $server)
732  {
733  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect#formmailbeforetitle">'.$langs->trans("DoTestServerAvailability").'</a>';
734  }
735  }
736  else
737  {
738  print '<a class="butActionRefused" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
739  }
740 
741  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&mode=init#formmailbeforetitle">'.$langs->trans("DoTestSend").'</a>';
742 
743  if (! empty($conf->fckeditor->enabled))
744  {
745  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testhtml&mode=init#formmailbeforetitle">'.$langs->trans("DoTestSendHTML").'</a>';
746  }
747 
748  print '</div>';
749 
750 
751  if ($conf->global->MAIN_MAIL_SENDMODE == 'mail' && empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA))
752  {
753  /*
754  // Warning 1
755  if ($linuxlike)
756  {
757  $sendmailoption=ini_get('mail.force_extra_parameters');
758  if (empty($sendmailoption) || ! preg_match('/ba/',$sendmailoption))
759  {
760  print info_admin($langs->trans("SendmailOptionNotComplete"));
761  }
762  }*/
763  // Warning 2
764  print info_admin($langs->trans("SendmailOptionMayHurtBuggedMTA"));
765  }
766 
767  if (! in_array($action, array('testconnect', 'test', 'testhtml')))
768  {
769  $text = '';
770  if ($conf->global->MAIN_MAIL_SENDMODE == 'mail')
771  {
772  $text.= $langs->trans("WarningPHPMail");
773  }
774  //$conf->global->MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS='1.2.3.4';
775  if (! empty($conf->global->MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS))
776  {
777  $text.= ($text?'<br>':'').$langs->trans("WarningPHPMail2", $conf->global->MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS);
778  }
779  if ($text) print info_admin($text);
780  }
781 
782  // Run the test to connect
783  if ($action == 'testconnect')
784  {
785  print load_fiche_titre($langs->trans("DoTestServerAvailability"));
786 
787  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
788  $mail = new CMailFile('','','','');
789  $result=$mail->check_server_port($server,$port);
790  if ($result) print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort",$server,$port).'</div>';
791  else
792  {
793  $errormsg = $langs->trans("ServerNotAvailableOnIPOrPort",$server,$port);
794 
795  if ($mail->error) {
796  $errormsg .= ' - '.$mail->error;
797  }
798 
799  setEventMessages($errormsg, null, 'errors');
800  }
801  print '<br>';
802  }
803 
804  // Show email send test form
805  if ($action == 'test' || $action == 'testhtml')
806  {
807  print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
808  print load_fiche_titre($action == 'testhtml'?$langs->trans("DoTestSendHTML"):$langs->trans("DoTestSend"));
809 
810  dol_fiche_head('');
811 
812  // Cree l'objet formulaire mail
813  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
814  $formmail = new FormMail($db);
815  $formmail->trackid=(($action == 'testhtml')?"testhtml":"test");
816  $formmail->fromname = (isset($_POST['fromname'])?$_POST['fromname']:$conf->global->MAIN_MAIL_EMAIL_FROM);
817  $formmail->frommail = (isset($_POST['frommail'])?$_POST['frommail']:$conf->global->MAIN_MAIL_EMAIL_FROM);
818  $formmail->fromid=$user->id;
819  $formmail->fromalsorobot=1;
820  $formmail->fromtype=(GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
821  $formmail->withfromreadonly=1;
822  $formmail->withsubstit=1;
823  $formmail->withfrom=1;
824  $formmail->witherrorsto=1;
825  $formmail->withto=(! empty($_POST['sendto'])?$_POST['sendto']:($user->email?$user->email:1));
826  $formmail->withtocc=(! empty($_POST['sendtocc'])?$_POST['sendtocc']:1); // ! empty to keep field if empty
827  $formmail->withtoccc=(! empty($_POST['sendtoccc'])?$_POST['sendtoccc']:1); // ! empty to keep field if empty
828  $formmail->withtopic=(isset($_POST['subject'])?$_POST['subject']:$langs->trans("Test"));
829  $formmail->withtopicreadonly=0;
830  $formmail->withfile=2;
831  $formmail->withbody=(isset($_POST['message'])?$_POST['message']:($action == 'testhtml'?$langs->transnoentities("PredefinedMailTestHtml"):$langs->transnoentities("PredefinedMailTest")));
832  $formmail->withbodyreadonly=0;
833  $formmail->withcancel=1;
834  $formmail->withdeliveryreceipt=1;
835  $formmail->withfckeditor=($action == 'testhtml'?1:0);
836  $formmail->ckeditortoolbar='dolibarr_mailings';
837  // Tableau des substitutions
838  $formmail->substit=$substitutionarrayfortest;
839  // Tableau des parametres complementaires du post
840  $formmail->param["action"]="send";
841  $formmail->param["models"]="body";
842  $formmail->param["mailid"]=0;
843  $formmail->param["returnurl"]=$_SERVER["PHP_SELF"];
844 
845  // Init list of files
846  if (GETPOST("mode")=='init')
847  {
848  $formmail->clear_attached_files();
849  }
850 
851  print $formmail->get_form('addfile','removefile');
852 
853  dol_fiche_end();
854  }
855 }
856 
857 // End of page
858 llxFooter();
859 $db->close();
img_warning($titlealt='default', $moreatt='')
Show warning logo.
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
email_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: admin.lib.php:1730
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:510
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='')
Show information for admin users or standard users.
dol_fiche_end($notab=0)
Show tab footer of a card.
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); $mailfile->sendfile();.
llxHeader()
Empty header.
Definition: wrapper.php:44
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0)
Clean a string from all HTML tags and entities.
Class for EmailSenderProfile.
isValidEmail($address, $acceptsupervisorkey=0)
Return true if email syntax is ok.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
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...
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $wikihelp
View.
Definition: agenda.php:120