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