dolibarr  7.0.0-beta
mails_emailing.php
1 <?php
2 /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@capnetworks.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 $langs->load("companies");
31 $langs->load("products");
32 $langs->load("admin");
33 $langs->load("mails");
34 $langs->load("other");
35 $langs->load("errors");
36 
37 $action=GETPOST('action','alpha');
38 
39 if (! $user->admin) accessforbidden();
40 
41 $usersignature=$user->signature;
42 // For action = test or send, we ensure that content is not html, even for signature, because this we want a test with NO html.
43 if ($action == 'test' || $action == 'send')
44 {
45  $usersignature=dol_string_nohtmltag($usersignature);
46 }
47 
48 $substitutionarrayfortest=array(
49 '__LOGIN__' => $user->login,
50 '__ID__' => 'TESTIdRecord',
51 '__EMAIL__' => 'TESTEMail',
52 '__LASTNAME__' => 'TESTLastname',
53 '__FIRSTNAME__' => 'TESTFirstname',
54 '__USER_SIGNATURE__' => (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))?$usersignature:''),
55 //'__PERSONALIZED__' => 'TESTPersonalized' // Hiden because not used yet
56 );
57 complete_substitutions_array($substitutionarrayfortest, $langs);
58 
59 
60 
61 /*
62  * Actions
63  */
64 
65 if ($action == 'update' && empty($_POST["cancel"]))
66 {
67  // Send mode parameters
68  dolibarr_set_const($db, "MAIN_MAIL_SENDMODE_EMAILING", GETPOST("MAIN_MAIL_SENDMODE_EMAILING"),'chaine',0,'',$conf->entity);
69  dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT_EMAILING", GETPOST("MAIN_MAIL_SMTP_PORT_EMAILING"),'chaine',0,'',$conf->entity);
70  dolibarr_set_const($db, "MAIN_MAIL_SMTP_SERVER_EMAILING", GETPOST("MAIN_MAIL_SMTP_SERVER_EMAILING"),'chaine',0,'',$conf->entity);
71  dolibarr_set_const($db, "MAIN_MAIL_SMTPS_ID_EMAILING", GETPOST("MAIN_MAIL_SMTPS_ID_EMAILING"), 'chaine',0,'',$conf->entity);
72  dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW_EMAILING", GETPOST("MAIN_MAIL_SMTPS_PW_EMAILING"), 'chaine',0,'',$conf->entity);
73  dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS_EMAILING", GETPOST("MAIN_MAIL_EMAIL_TLS_EMAILING"),'chaine',0,'',$conf->entity);
74  dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS_EMAILING", GETPOST("MAIN_MAIL_EMAIL_STARTTLS_EMAILING"),'chaine',0,'',$conf->entity);
75 
76  header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
77  exit;
78 }
79 
80 
81 // Actions to send emails
82 $id=0;
83 $actiontypecode=''; // Not an event for agenda
84 $trigger_name=''; // Disable triggers
85 $paramname='id';
86 $mode='emailfortest';
87 $trackid=(($action == 'testhtml')?"testhtml":"test");
88 $sendcontext='emailing'; // Force to use dedicated context of setup for emailing
89 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
90 
91 if ($action == 'presend' && GETPOST('trackid') == 'test') $action='test';
92 if ($action == 'presend' && GETPOST('trackid') == 'testhtml') $action='testhtml';
93 
94 
95 
96 
97 /*
98  * View
99  */
100 
101 $linuxlike=1;
102 if (preg_match('/^win/i',PHP_OS)) $linuxlike=0;
103 if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0;
104 
105 if (empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING)) $conf->global->MAIN_MAIL_SENDMODE_EMAILING='default';
106 $port=! empty($conf->global->MAIN_MAIL_SMTP_PORT_EMAILING)?$conf->global->MAIN_MAIL_SMTP_PORT_EMAILING:ini_get('smtp_port');
107 if (! $port) $port=25;
108 $server=! empty($conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING)?$conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING:ini_get('SMTP');
109 if (! $server) $server='127.0.0.1';
110 
111 
112 $wikihelp='EN:Setup_EMails|FR:Paramétrage_EMails|ES:Configuración_EMails';
113 llxHeader('',$langs->trans("Setup"),$wikihelp);
114 
115 print load_fiche_titre($langs->trans("EMailsSetup"),'','title_setup');
116 
117 $head = email_admin_prepare_head();
118 
119 // List of sending methods
120 $listofmethods=array();
121 $listofmethods['default']=$langs->trans('DefaultOutgoingEmailSetup');
122 $listofmethods['mail']='PHP mail function';
123 //$listofmethods['simplemail']='Simplemail class';
124 $listofmethods['smtps']='SMTP/SMTPS socket library';
125 $listofmethods['swiftmailer']='Swift Mailer socket library';
126 
127 
128 if ($action == 'edit')
129 {
130  $form=new Form($db);
131 
132  if ($conf->use_javascript_ajax)
133  {
134  print "\n".'<script type="text/javascript" language="javascript">';
135  print 'jQuery(document).ready(function () {
136  function initfields()
137  {
138  if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'default\')
139  {
140  jQuery(".hideifdefault").hide();
141  }
142  else
143  {
144  jQuery(".hideifdefault").show();
145  }
146 
147  if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'mail\')
148  {
149  jQuery(".drag").hide();
150  jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val(0);
151  jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").prop("disabled", true);
152  jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val(0);
153  jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").prop("disabled", true);
154  ';
155  if ($linuxlike)
156  {
157  print '
158  jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").hide();
159  jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").hide();
160  jQuery("#smtp_server_mess").show();
161  jQuery("#smtp_port_mess").show();
162  ';
163  }
164  else
165  {
166  print '
167  jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").prop("disabled", true);
168  jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").prop("disabled", true);
169  jQuery("#smtp_server_mess").hide();
170  jQuery("#smtp_port_mess").hide();
171  ';
172  }
173  print '
174  }
175  if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'smtps\')
176  {
177  jQuery(".drag").show();
178  jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING.');
179  jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").removeAttr("disabled");
180  jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING.');
181  jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").removeAttr("disabled");
182  jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").removeAttr("disabled");
183  jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").removeAttr("disabled");
184  jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").show();
185  jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").show();
186  jQuery("#smtp_server_mess").hide();
187  jQuery("#smtp_port_mess").hide();
188  }
189  if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'swiftmailer\')
190  {
191  jQuery(".drag").show();
192  jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING.');
193  jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").removeAttr("disabled");
194  jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING.');
195  jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").removeAttr("disabled");
196  jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").removeAttr("disabled");
197  jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").removeAttr("disabled");
198  jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").show();
199  jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").show();
200  jQuery("#smtp_server_mess").hide();
201  jQuery("#smtp_port_mess").hide();
202  }
203  }
204  initfields();
205  jQuery("#MAIN_MAIL_SENDMODE_EMAILING").change(function() {
206  initfields();
207  });
208  jQuery("#MAIN_MAIL_EMAIL_TLS").change(function() {
209  if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val() == 1)
210  jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val(0);
211  });
212  jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").change(function() {
213  if (jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val() == 1)
214  jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val(0);
215  });
216  })';
217  print '</script>'."\n";
218  }
219 
220  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
221  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
222  print '<input type="hidden" name="action" value="update">';
223 
224  dol_fiche_head($head, 'common_emailing', '', -1);
225 
226  print $langs->trans("EMailsDesc")."<br>\n";
227  print "<br>\n";
228 
229 
230  clearstatcache();
231  $var=true;
232 
233  print '<table class="noborder" width="100%">';
234  print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
235 
236  // Method
237 
238  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
239 
240  // SuperAdministrator access only
241  if ((empty($conf->global->MAIN_MODULE_MULTICOMPANY)) || ($user->admin && !$user->entity))
242  {
243  print $form->selectarray('MAIN_MAIL_SENDMODE_EMAILING',$listofmethods,$conf->global->MAIN_MAIL_SENDMODE_EMAILING);
244  }
245  else
246  {
247  $text = $listofmethods[$conf->global->MAIN_MAIL_SENDMODE_EMAILING];
248  if (empty($text)) $text = $langs->trans("Undefined");
249  $htmltext = $langs->trans("ContactSuperAdminForChange");
250  print $form->textwithpicto($text,$htmltext,1,'superadmin');
251  print '<input type="hidden" name="MAIN_MAIL_SENDMODE_EMAILING" value="'.$conf->global->MAIN_MAIL_SENDMODE_EMAILING.'">';
252  }
253  print '</td></tr>';
254 
255  // Host server
256 
257  print '<tr class="oddeven hideifdefault"><td>';
258  if (! $conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail')
259  {
260  print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
261  print '</td><td>';
262  print $langs->trans("SeeLocalSendMailSetup");
263  }
264  else
265  {
266  $mainserver = (! empty($conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING)?$conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING:'');
267  $smtpserver = ini_get('SMTP')?ini_get('SMTP'):$langs->transnoentities("Undefined");
268  if ($linuxlike) print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
269  else print $langs->trans("MAIN_MAIL_SMTP_SERVER",$smtpserver);
270  print '</td><td>';
271  // SuperAdministrator access only
272  if (empty($conf->multicompany->enabled) || ($user->admin && ! $user->entity))
273  {
274  print '<input class="flat" id="MAIN_MAIL_SMTP_SERVER_EMAILING" name="MAIN_MAIL_SMTP_SERVER_EMAILING" size="18" value="' . $mainserver . '">';
275  print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_EMAILING_sav" name="MAIN_MAIL_SMTP_SERVER_EMAILING_sav" value="' . $mainserver . '">';
276  print '<span id="smtp_server_mess">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
277  }
278  else
279  {
280  $text = ! empty($mainserver) ? $mainserver : $smtpserver;
281  $htmltext = $langs->trans("ContactSuperAdminForChange");
282  print $form->textwithpicto($text,$htmltext,1,'superadmin');
283  print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_EMAILING" name="MAIN_MAIL_SMTP_SERVER_EMAILING" value="'.$mainserver.'">';
284  }
285  }
286  print '</td></tr>';
287 
288  // Port
289 
290  print '<tr class="oddeven hideifdefault"><td>';
291  if (! $conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail')
292  {
293  print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
294  print '</td><td>';
295  print $langs->trans("SeeLocalSendMailSetup");
296  }
297  else
298  {
299  $mainport = (! empty($conf->global->MAIN_MAIL_SMTP_PORT_EMAILING) ? $conf->global->MAIN_MAIL_SMTP_PORT_EMAILING : '');
300  $smtpport = ini_get('smtp_port')?ini_get('smtp_port'):$langs->transnoentities("Undefined");
301  if ($linuxlike) print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
302  else print $langs->trans("MAIN_MAIL_SMTP_PORT",$smtpport);
303  print '</td><td>';
304  // SuperAdministrator access only
305  if (empty($conf->multicompany->enabled) || ($user->admin && ! $user->entity))
306  {
307  print '<input class="flat" id="MAIN_MAIL_SMTP_PORT_EMAILING" name="MAIN_MAIL_SMTP_PORT_EMAILING" size="3" value="' . $mainport . '">';
308  print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_EMAILING_sav" name="MAIN_MAIL_SMTP_PORT_EMAILING_sav" value="' . $mainport . '">';
309  print '<span id="smtp_port_mess">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
310  }
311  else
312  {
313  $text = (! empty($mainport) ? $mainport : $smtpport);
314  $htmltext = $langs->trans("ContactSuperAdminForChange");
315  print $form->textwithpicto($text,$htmltext,1,'superadmin');
316  print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_EMAILING" name="MAIN_MAIL_SMTP_PORT_EMAILING" value="'.$mainport.'">';
317  }
318  }
319  print '</td></tr>';
320 
321  // ID
322  if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))))
323  {
324 
325  $mainstmpid=(! empty($conf->global->MAIN_MAIL_SMTPS_ID_EMAILING)?$conf->global->MAIN_MAIL_SMTPS_ID_EMAILING:'');
326  print '<tr class="drag drop oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>';
327  // SuperAdministrator access only
328  if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity))
329  {
330  print '<input class="flat" name="MAIN_MAIL_SMTPS_ID_EMAILING" size="32" value="' . $mainstmpid . '">';
331  }
332  else
333  {
334  $htmltext = $langs->trans("ContactSuperAdminForChange");
335  print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_ID_EMAILING,$htmltext,1,'superadmin');
336  print '<input type="hidden" name="MAIN_MAIL_SMTPS_ID_EMAILING" value="'.$mainstmpid.'">';
337  }
338  print '</td></tr>';
339  }
340 
341  // PW
342  if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))))
343  {
344 
345  $mainsmtppw=(! empty($conf->global->MAIN_MAIL_SMTPS_PW_EMAILING)?$conf->global->MAIN_MAIL_SMTPS_PW_EMAILING:'');
346  print '<tr class="drag drop oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>';
347  // SuperAdministrator access only
348  if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity))
349  {
350  print '<input class="flat" type="password" name="MAIN_MAIL_SMTPS_PW_EMAILING" size="32" value="' . $mainsmtppw . '">';
351  }
352  else
353  {
354  $htmltext = $langs->trans("ContactSuperAdminForChange");
355  print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_PW_EMAILING,$htmltext,1,'superadmin');
356  print '<input type="hidden" name="MAIN_MAIL_SMTPS_PW_EMAILING" value="'.$mainsmtppw.'">';
357  }
358  print '</td></tr>';
359  }
360 
361  // TLS
362 
363  print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
364  if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))))
365  {
366  if (function_exists('openssl_open'))
367  {
368  print $form->selectyesno('MAIN_MAIL_EMAIL_TLS_EMAILING',(! empty($conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING)?$conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING:0),1);
369  }
370  else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
371  }
372  else print yn(0).' ('.$langs->trans("NotSupported").')';
373  print '</td></tr>';
374 
375  // STARTTLS
376 
377  print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
378  if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))))
379  {
380  if (function_exists('openssl_open'))
381  {
382  print $form->selectyesno('MAIN_MAIL_EMAIL_STARTTLS_EMAILING',(! empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING)?$conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING:0),1);
383  }
384  else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
385  }
386  else print yn(0).' ('.$langs->trans("NotSupported").')';
387  print '</td></tr>';
388 
389  print '</table>';
390 
391  dol_fiche_end();
392 
393  print '<br><div class="center">';
394  print '<input class="button" type="submit" name="save" value="'.$langs->trans("Save").'">';
395  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
396  print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
397  print '</div>';
398 
399  print '</form>';
400 }
401 else
402 {
403  dol_fiche_head($head, 'common_emailing', '', -1);
404 
405  print $langs->trans("EMailsDesc")."<br>\n";
406  print "<br>\n";
407 
408 
409  $var=true;
410 
411  print '<table class="noborder" width="100%">';
412  print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
413 
414  // Method
415 
416  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
417  $text=$listofmethods[$conf->global->MAIN_MAIL_SENDMODE_EMAILING];
418  if (empty($text)) $text=$langs->trans("Undefined").img_warning();
419  print $text;
420  print '</td></tr>';
421 
422  if (! empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default')
423  {
424  // Host server
425 
426  if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail'))
427  {
428  print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
429  }
430  else
431  {
432  print '<tr class="oddeven hideifdefault"><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_EMAILING)?$conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING:'').'</td></tr>';
433  }
434 
435  // Port
436 
437  if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail'))
438  {
439  print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
440  }
441  else
442  {
443  print '<tr class="oddeven hideifdefault"><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_EMAILING)?$conf->global->MAIN_MAIL_SMTP_PORT_EMAILING:'').'</td></tr>';
444  }
445 
446  // SMTPS ID
447 
448  if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))
449  {
450  print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>'.$conf->global->MAIN_MAIL_SMTPS_ID_EMAILING.'</td></tr>';
451  }
452 
453  // SMTPS PW
454 
455  if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))
456  {
457  print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>'.preg_replace('/./','*',$conf->global->MAIN_MAIL_SMTPS_PW_EMAILING).'</td></tr>';
458  }
459 
460  // TLS
461 
462  print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
463  if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))
464  {
465  if (function_exists('openssl_open'))
466  {
467  print yn($conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING);
468  }
469  else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
470  }
471  else print yn(0).' ('.$langs->trans("NotSupported").')';
472  print '</td></tr>';
473 
474  // STARTTLS
475 
476  print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
477  if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))
478  {
479  if (function_exists('openssl_open'))
480  {
481  print yn($conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING);
482  }
483  else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
484  }
485  else print yn(0).' ('.$langs->trans("NotSupported").')';
486  print '</td></tr>';
487  }
488 
489  print '</table>';
490 
491  dol_fiche_end();
492 
493 
494  if ($conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail' && empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA))
495  {
496  print '<br>';
497  /*
498  // Warning 1
499  if ($linuxlike)
500  {
501  $sendmailoption=ini_get('mail.force_extra_parameters');
502  if (empty($sendmailoption) || ! preg_match('/ba/',$sendmailoption))
503  {
504  print info_admin($langs->trans("SendmailOptionNotComplete"));
505  }
506  }*/
507  // Warning 2
508  print info_admin($langs->trans("SendmailOptionMayHurtBuggedMTA"));
509  }
510 
511 
512  // Boutons actions
513  print '<div class="tabsAction">';
514 
515  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
516 
517  if (! empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default')
518  {
519  if ($conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'mail' || ! $linuxlike)
520  {
521  if (function_exists('fsockopen') && $port && $server)
522  {
523  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
524  }
525  }
526  else
527  {
528  print '<a class="butActionRefused" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
529  }
530 
531  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&amp;mode=init">'.$langs->trans("DoTestSend").'</a>';
532 
533  if (! empty($conf->fckeditor->enabled))
534  {
535  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testhtml&amp;mode=init">'.$langs->trans("DoTestSendHTML").'</a>';
536  }
537  }
538 
539  print '</div>';
540 
541 
542  if ($conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail' && ! in_array($action, array('testconnect', 'test', 'testhtml')))
543  {
544  $text = $langs->trans("WarningPHPMail");
545  print info_admin($text);
546  }
547 
548  // Run the test to connect
549  if ($action == 'testconnect')
550  {
551  print load_fiche_titre($langs->trans("DoTestServerAvailability"));
552 
553  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
554  $mail = new CMailFile('','','','');
555  $result=$mail->check_server_port($server,$port);
556  if ($result) print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort",$server,$port).'</div>';
557  else
558  {
559  $errormsg = $langs->trans("ServerNotAvailableOnIPOrPort",$server,$port);
560 
561  if ($mail->error) {
562  $errormsg .= ' - '.$mail->error;
563  }
564 
565  setEventMessages($errormsg, null, 'errors');
566  }
567  print '<br>';
568  }
569 
570  // Show email send test form
571  if ($action == 'test' || $action == 'testhtml')
572  {
573  print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
574  print load_fiche_titre($action == 'testhtml'?$langs->trans("DoTestSendHTML"):$langs->trans("DoTestSend"));
575 
576  dol_fiche_head('');
577 
578  // Cree l'objet formulaire mail
579  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
580  $formmail = new FormMail($db);
581  $formmail->fromname = (isset($_POST['fromname'])?$_POST['fromname']:$conf->global->MAIN_MAIL_EMAIL_FROM);
582  $formmail->frommail = (isset($_POST['frommail'])?$_POST['frommail']:$conf->global->MAIN_MAIL_EMAIL_FROM);
583  $formmail->trackid=(($action == 'testhtml')?"testhtml":"test");
584  $formmail->withfromreadonly=0;
585  $formmail->withsubstit=0;
586  $formmail->withfrom=1;
587  $formmail->witherrorsto=1;
588  $formmail->withto=(! empty($_POST['sendto'])?$_POST['sendto']:($user->email?$user->email:1));
589  $formmail->withtocc=(! empty($_POST['sendtocc'])?$_POST['sendtocc']:1); // ! empty to keep field if empty
590  $formmail->withtoccc=(! empty($_POST['sendtoccc'])?$_POST['sendtoccc']:1); // ! empty to keep field if empty
591  $formmail->withtopic=(isset($_POST['subject'])?$_POST['subject']:$langs->trans("Test"));
592  $formmail->withtopicreadonly=0;
593  $formmail->withfile=2;
594  $formmail->withbody=(isset($_POST['message'])?$_POST['message']:($action == 'testhtml'?$langs->transnoentities("PredefinedMailTestHtml"):$langs->transnoentities("PredefinedMailTest")));
595  $formmail->withbodyreadonly=0;
596  $formmail->withcancel=1;
597  $formmail->withdeliveryreceipt=1;
598  $formmail->withfckeditor=($action == 'testhtml'?1:0);
599  $formmail->ckeditortoolbar='dolibarr_mailings';
600  // Tableau des substitutions
601  $formmail->substit=$substitutionarrayfortest;
602  // Tableau des parametres complementaires du post
603  $formmail->param["action"]="send";
604  $formmail->param["models"]="body";
605  $formmail->param["mailid"]=0;
606  $formmail->param["returnurl"]=$_SERVER["PHP_SELF"];
607 
608  // Init list of files
609  if (GETPOST("mode")=='init')
610  {
611  $formmail->clear_attached_files();
612  }
613 
614  print $formmail->get_form('addfile','removefile');
615 
616  dol_fiche_end();
617  }
618 }
619 
620 
621 llxFooter();
622 
623 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
email_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: admin.lib.php:1600
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:485
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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')
Show information for admin users or standard users.
if(GETPOST('button_removefilter_x','alpha')||GETPOST('button_removefilter.x','alpha')||GETPOST('button_removefilter','alpha')) if($action=="save"&&empty($cancel)) if(preg_match('/set_(.*)/', $action, $reg)) if(preg_match('/del_(.*)/', $action, $reg) $wikihelp)
View.
Definition: agenda.php:143
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();.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8')
Clean a string from all HTML tags and entities.
print
Draft customers invoices.
Definition: index.php:91
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...