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