dolibarr  13.0.2
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 <https://www.gnu.org/licenses/>.
19  */
20 
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
29 
30 // Load translation files required by the page
31 $langs->loadLangs(array('companies', 'products', 'admin', 'mails', 'other', 'errors'));
32 
33 $action = GETPOST('action', 'aZ09');
34 
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  dolibarr_set_const($db, "MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING", GETPOST("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING"), 'chaine', 0, '', $conf->entity);
72 
73  header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
74  exit;
75 }
76 
77 
78 // Actions to send emails
79 $id = 0;
80 $actiontypecode = ''; // Not an event for agenda
81 $triggersendname = ''; // Disable triggers
82 $paramname = 'id';
83 $mode = 'emailfortest';
84 $trackid = (($action == 'testhtml') ? "testhtml" : "test");
85 $sendcontext = 'emailing'; // Force to use dedicated context of setup for emailing
86 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
87 
88 if ($action == 'presend' && GETPOST('trackid') == 'test') $action = 'test';
89 if ($action == 'presend' && GETPOST('trackid') == 'testhtml') $action = 'testhtml';
90 
91 
92 
93 
94 /*
95  * View
96  */
97 
98 $form = new Form($db);
99 
100 $linuxlike = 1;
101 if (preg_match('/^win/i', PHP_OS)) $linuxlike = 0;
102 if (preg_match('/^mac/i', PHP_OS)) $linuxlike = 0;
103 
104 if (empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING)) $conf->global->MAIN_MAIL_SENDMODE_EMAILING = 'default';
105 $port = !empty($conf->global->MAIN_MAIL_SMTP_PORT_EMAILING) ? $conf->global->MAIN_MAIL_SMTP_PORT_EMAILING : ini_get('smtp_port');
106 if (!$port) $port = 25;
107 $server = !empty($conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING) ? $conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING : ini_get('SMTP');
108 if (!$server) $server = '127.0.0.1';
109 
110 
111 $wikihelp = 'EN:Setup_EMails|FR:Paramétrage_EMails|ES:Configuración_EMails';
112 llxHeader('', $langs->trans("Setup"), $wikihelp);
113 
114 print load_fiche_titre($langs->trans("EMailsSetup"), '', 'title_setup');
115 
116 $head = email_admin_prepare_head();
117 
118 // List of sending methods
119 $listofmethods = array();
120 $listofmethods['default'] = $langs->trans('DefaultOutgoingEmailSetup');
121 $listofmethods['mail'] = 'PHP mail function';
122 //$listofmethods['simplemail']='Simplemail class';
123 $listofmethods['smtps'] = 'SMTP/SMTPS socket library';
124 if (version_compare(phpversion(), '7.0', '>=')) $listofmethods['swiftmailer'] = 'Swift Mailer socket library';
125 
126 
127 if ($action == 'edit')
128 {
129  if ($conf->use_javascript_ajax)
130  {
131  print "\n".'<script type="text/javascript" language="javascript">';
132  print 'jQuery(document).ready(function () {
133  function initfields()
134  {
135  if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'default\')
136  {
137  jQuery(".hideifdefault").hide();
138  }
139  else
140  {
141  jQuery(".hideifdefault").show();
142  }
143 
144  if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'mail\')
145  {
146  jQuery(".drag").hide();
147  jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val(0);
148  jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").prop("disabled", true);
149  jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val(0);
150  jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").prop("disabled", true);
151  jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val(0);
152  jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").prop("disabled", true);
153  ';
154  if ($linuxlike)
155  {
156  print '
157  jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").hide();
158  jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").hide();
159  jQuery("#smtp_server_mess").show();
160  jQuery("#smtp_port_mess").show();
161  ';
162  } else {
163  print '
164  jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").prop("disabled", true);
165  jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").prop("disabled", true);
166  jQuery("#smtp_server_mess").hide();
167  jQuery("#smtp_port_mess").hide();
168  ';
169  }
170  print '
171  }
172  if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'smtps\')
173  {
174  jQuery(".drag").show();
175  jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING.');
176  jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").removeAttr("disabled");
177  jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING.');
178  jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").removeAttr("disabled");
179  jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING.');
180  jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").removeAttr("disabled");
181  jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").removeAttr("disabled");
182  jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").removeAttr("disabled");
183  jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").show();
184  jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").show();
185  jQuery("#smtp_server_mess").hide();
186  jQuery("#smtp_port_mess").hide();
187  }
188  if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'swiftmailer\')
189  {
190  jQuery(".drag").show();
191  jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING.');
192  jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").removeAttr("disabled");
193  jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING.');
194  jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").removeAttr("disabled");
195  jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING.');
196  jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").removeAttr("disabled");
197  jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").removeAttr("disabled");
198  jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").removeAttr("disabled");
199  jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").show();
200  jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").show();
201  jQuery("#smtp_server_mess").hide();
202  jQuery("#smtp_port_mess").hide();
203  }
204  }
205  initfields();
206  jQuery("#MAIN_MAIL_SENDMODE_EMAILING").change(function() {
207  initfields();
208  });
209  jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").change(function() {
210  if (jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val() == 1)
211  jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val(0);
212  else
213  jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val(0);
214  });
215  jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").change(function() {
216  if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val() == 1)
217  jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val(0);
218  else
219  jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val(0);
220  });
221  })';
222  print '</script>'."\n";
223  }
224 
225  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
226  print '<input type="hidden" name="token" value="'.newToken().'">';
227  print '<input type="hidden" name="action" value="update">';
228 
229  print dol_get_fiche_head($head, 'common_emailing', '', -1);
230 
231  print '<span class="opacitymedium">'.$langs->trans("EMailsDesc")."</span><br>\n";
232  print "<br>\n";
233 
234 
235  clearstatcache();
236 
237  print '<table class="noborder centpercent">';
238  print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
239 
240  // Method
241 
242  print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
243 
244  // SuperAdministrator access only
245  if ((empty($conf->global->MAIN_MODULE_MULTICOMPANY)) || ($user->admin && !$user->entity))
246  {
247  print $form->selectarray('MAIN_MAIL_SENDMODE_EMAILING', $listofmethods, $conf->global->MAIN_MAIL_SENDMODE_EMAILING);
248  } else {
249  $text = $listofmethods[$conf->global->MAIN_MAIL_SENDMODE_EMAILING];
250  if (empty($text)) $text = $langs->trans("Undefined");
251  $htmltext = $langs->trans("ContactSuperAdminForChange");
252  print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
253  print '<input type="hidden" name="MAIN_MAIL_SENDMODE_EMAILING" value="'.$conf->global->MAIN_MAIL_SENDMODE_EMAILING.'">';
254  }
255  print '</td></tr>';
256 
257  // Host server
258 
259  print '<tr class="oddeven hideifdefault"><td>';
260  if (!$conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail')
261  {
262  print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
263  print '</td><td>';
264  print $langs->trans("SeeLocalSendMailSetup");
265  } else {
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  } else {
278  $text = !empty($mainserver) ? $mainserver : $smtpserver;
279  $htmltext = $langs->trans("ContactSuperAdminForChange");
280  print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
281  print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_EMAILING" name="MAIN_MAIL_SMTP_SERVER_EMAILING" value="'.$mainserver.'">';
282  }
283  }
284  print '</td></tr>';
285 
286  // Port
287 
288  print '<tr class="oddeven hideifdefault"><td>';
289  if (!$conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail')
290  {
291  print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
292  print '</td><td>';
293  print $langs->trans("SeeLocalSendMailSetup");
294  } else {
295  $mainport = (!empty($conf->global->MAIN_MAIL_SMTP_PORT_EMAILING) ? $conf->global->MAIN_MAIL_SMTP_PORT_EMAILING : '');
296  $smtpport = ini_get('smtp_port') ?ini_get('smtp_port') : $langs->transnoentities("Undefined");
297  if ($linuxlike) print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
298  else print $langs->trans("MAIN_MAIL_SMTP_PORT", $smtpport);
299  print '</td><td>';
300  // SuperAdministrator access only
301  if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity))
302  {
303  print '<input class="flat" id="MAIN_MAIL_SMTP_PORT_EMAILING" name="MAIN_MAIL_SMTP_PORT_EMAILING" size="3" value="'.$mainport.'">';
304  print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_EMAILING_sav" name="MAIN_MAIL_SMTP_PORT_EMAILING_sav" value="'.$mainport.'">';
305  print '<span id="smtp_port_mess">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
306  } else {
307  $text = (!empty($mainport) ? $mainport : $smtpport);
308  $htmltext = $langs->trans("ContactSuperAdminForChange");
309  print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
310  print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_EMAILING" name="MAIN_MAIL_SMTP_PORT_EMAILING" value="'.$mainport.'">';
311  }
312  }
313  print '</td></tr>';
314 
315  // ID
316  if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))))
317  {
318  $mainstmpid = (!empty($conf->global->MAIN_MAIL_SMTPS_ID_EMAILING) ? $conf->global->MAIN_MAIL_SMTPS_ID_EMAILING : '');
319  print '<tr class="drag drop oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>';
320  // SuperAdministrator access only
321  if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity))
322  {
323  print '<input class="flat" name="MAIN_MAIL_SMTPS_ID_EMAILING" size="32" value="'.$mainstmpid.'">';
324  } else {
325  $htmltext = $langs->trans("ContactSuperAdminForChange");
326  print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_ID_EMAILING, $htmltext, 1, 'superadmin');
327  print '<input type="hidden" name="MAIN_MAIL_SMTPS_ID_EMAILING" value="'.$mainstmpid.'">';
328  }
329  print '</td></tr>';
330  }
331 
332  // PW
333  if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))))
334  {
335  $mainsmtppw = (!empty($conf->global->MAIN_MAIL_SMTPS_PW_EMAILING) ? $conf->global->MAIN_MAIL_SMTPS_PW_EMAILING : '');
336  print '<tr class="drag drop oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>';
337  // SuperAdministrator access only
338  if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity))
339  {
340  print '<input class="flat" type="password" name="MAIN_MAIL_SMTPS_PW_EMAILING" size="32" value="'.$mainsmtppw.'">';
341  } else {
342  $htmltext = $langs->trans("ContactSuperAdminForChange");
343  print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_PW_EMAILING, $htmltext, 1, 'superadmin');
344  print '<input type="hidden" name="MAIN_MAIL_SMTPS_PW_EMAILING" value="'.$mainsmtppw.'">';
345  }
346  print '</td></tr>';
347  }
348 
349  // TLS
350 
351  print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
352  if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))))
353  {
354  if (function_exists('openssl_open'))
355  {
356  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);
357  } else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
358  } else print yn(0).' ('.$langs->trans("NotSupported").')';
359  print '</td></tr>';
360 
361  // STARTTLS
362 
363  print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</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_STARTTLS_EMAILING', (!empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING) ? $conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING : 0), 1);
369  } else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
370  } else print yn(0).' ('.$langs->trans("NotSupported").')';
371  print '</td></tr>';
372 
373  // SMTP_ALLOW_SELF_SIGNED_EMAILING
374 
375  print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").'</td><td>';
376  if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))))
377  {
378  if (function_exists('openssl_open'))
379  {
380  print $form->selectyesno('MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING', (!empty($conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING) ? $conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING : 0), 1);
381  } else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
382  } else print yn(0).' ('.$langs->trans("NotSupported").')';
383  print '</td></tr>';
384 
385  print '</table>';
386 
388 
389  print '<br><div class="center">';
390  print '<input class="button button-save" type="submit" name="save" value="'.$langs->trans("Save").'">';
391  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
392  print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
393  print '</div>';
394 
395  print '</form>';
396 } else {
397  print dol_get_fiche_head($head, 'common_emailing', '', -1);
398 
399  print '<span class="opacitymedium">'.$langs->trans("EMailsDesc")."</span><br>\n";
400  print "<br>\n";
401 
402  print '<table class="noborder centpercent">';
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  } else {
419  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>';
420  }
421 
422  // Port
423  if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail'))
424  {
425  print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
426  } else {
427  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>';
428  }
429 
430  // SMTPS ID
431  if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))
432  {
433  print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>'.$conf->global->MAIN_MAIL_SMTPS_ID_EMAILING.'</td></tr>';
434  }
435 
436  // SMTPS PW
437  if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))
438  {
439  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>';
440  }
441 
442  // TLS
443  print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
444  if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))
445  {
446  if (function_exists('openssl_open'))
447  {
448  print yn($conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING);
449  } else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
450  } else print yn(0).' ('.$langs->trans("NotSupported").')';
451  print '</td></tr>';
452 
453  // STARTTLS
454  print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
455  if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))
456  {
457  if (function_exists('openssl_open'))
458  {
459  print yn($conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING);
460  } else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
461  } else print yn(0).' ('.$langs->trans("NotSupported").')';
462  print '</td></tr>';
463 
464  // SMTP_ALLOW_SELF_SIGNED_EMAILING
465  print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").'</td><td>';
466  if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))
467  {
468  if (function_exists('openssl_open'))
469  {
470  print yn($conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING);
471  } else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
472  } else print yn(0).' ('.$langs->trans("NotSupported").')';
473  print '</td></tr>';
474  }
475 
476  print '</table>';
477 
479 
480 
481  if ($conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail' && empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA))
482  {
483  print '<br>';
484  /*
485  // Warning 1
486  if ($linuxlike)
487  {
488  $sendmailoption=ini_get('mail.force_extra_parameters');
489  if (empty($sendmailoption) || ! preg_match('/ba/',$sendmailoption))
490  {
491  print info_admin($langs->trans("SendmailOptionNotComplete"));
492  }
493  }*/
494  // Warning 2
495  print info_admin($langs->trans("SendmailOptionMayHurtBuggedMTA"));
496  }
497 
498 
499  // Buttons for actions
500 
501  print '<div class="tabsAction">';
502 
503  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
504 
505  if (!empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default')
506  {
507  if ($conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'mail' || !$linuxlike)
508  {
509  if (function_exists('fsockopen') && $port && $server)
510  {
511  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
512  }
513  } else {
514  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
515  }
516 
517  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&amp;mode=init">'.$langs->trans("DoTestSend").'</a>';
518 
519  if (!empty($conf->fckeditor->enabled))
520  {
521  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testhtml&amp;mode=init">'.$langs->trans("DoTestSendHTML").'</a>';
522  }
523  }
524 
525  print '</div>';
526 
527 
528  if ($conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail' && !in_array($action, array('testconnect', 'test', 'testhtml')))
529  {
530  $text = $langs->trans("WarningPHPMail");
531  print info_admin($text);
532  }
533 
534  // Run the test to connect
535  if ($action == 'testconnect')
536  {
537  print load_fiche_titre($langs->trans("DoTestServerAvailability"));
538 
539  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
540  $mail = new CMailFile('', '', '', '', array(), array(), array(), '', '', 0, '', '', '', '', $trackid, $sendcontext);
541 
542  $result = $mail->check_server_port($server, $port);
543  if ($result) print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort", $server, $port).'</div>';
544  else {
545  $errormsg = $langs->trans("ServerNotAvailableOnIPOrPort", $server, $port);
546 
547  if ($mail->error) {
548  $errormsg .= ' - '.$mail->error;
549  }
550 
551  setEventMessages($errormsg, null, 'errors');
552  }
553  print '<br>';
554  }
555 
556  // Show email send test form
557  if ($action == 'test' || $action == 'testhtml')
558  {
559  print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
560  print load_fiche_titre($action == 'testhtml' ? $langs->trans("DoTestSendHTML") : $langs->trans("DoTestSend"));
561 
563 
564  // Cree l'objet formulaire mail
565  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
566  $formmail = new FormMail($db);
567  $formmail->fromname = (GETPOSTISSET('fromname') ? GETPOST('fromname', 'restricthtml') : $conf->global->MAIN_MAIL_EMAIL_FROM);
568  $formmail->frommail = (GETPOSTISSET('frommail') ? GETPOST('frommail', 'restricthtml') : $conf->global->MAIN_MAIL_EMAIL_FROM);
569  $formmail->trackid = (($action == 'testhtml') ? "testhtml" : "test");
570  $formmail->withfromreadonly = 0;
571  $formmail->withsubstit = 0;
572  $formmail->withfrom = 1;
573  $formmail->witherrorsto = 1;
574  $formmail->withto = (!GETPOST('sendto') ? GETPOST('sendto', 'restricthtml') : ($user->email ? $user->email : 1));
575  $formmail->withtocc = (!GETPOST(['sendtocc']) ? GETPOST('sendtocc', 'restricthtml') : 1); // ! empty to keep field if empty
576  $formmail->withtoccc = (!GETPOST(['sendtoccc']) ? GETPOST('sendtoccc', 'restricthtml') : 1); // ! empty to keep field if empty
577  $formmail->withtopic = (GETPOSTISSET('subject') ? GETPOST('subject') : $langs->trans("Test"));
578  $formmail->withtopicreadonly = 0;
579  $formmail->withfile = 2;
580  $formmail->withbody = (GETPOSTISSET('message') ? GETPOST('message', 'restricthtml') : ($action == 'testhtml' ? $langs->transnoentities("PredefinedMailTestHtml") : $langs->transnoentities("PredefinedMailTest")));
581  $formmail->withbodyreadonly = 0;
582  $formmail->withcancel = 1;
583  $formmail->withdeliveryreceipt = 1;
584  $formmail->withfckeditor = ($action == 'testhtml' ? 1 : 0);
585  $formmail->ckeditortoolbar = 'dolibarr_mailings';
586  // Tableau des substitutions
587  $formmail->substit = $substitutionarrayfortest;
588  // Tableau des parametres complementaires du post
589  $formmail->param["action"] = "send";
590  $formmail->param["models"] = "body";
591  $formmail->param["mailid"] = 0;
592  $formmail->param["returnurl"] = $_SERVER["PHP_SELF"];
593 
594  // Init list of files
595  if (GETPOST("mode") == 'init')
596  {
597  $formmail->clear_attached_files();
598  }
599 
600  print $formmail->get_form('addfile', 'removefile');
601 
603  }
604 }
605 
606 // End of page
607 llxFooter();
608 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
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.
email_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: admin.lib.php:1845
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:575
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
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext,$replyto); $mailfile-&gt;sendfile();.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_get_fiche_end($notab=0)
Return tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the &quot;subst...