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