PageRenderTime 51ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/admin/mails.php

https://bitbucket.org/speedealing/speedealing
PHP | 757 lines | 557 code | 103 blank | 97 comment | 149 complexity | b251793a9916743ecb37c393d8621d6b MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/admin/mails.php
  20. * \brief Page to setup emails sending
  21. */
  22. require '../main.inc.php';
  23. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  25. $langs->load("companies");
  26. $langs->load("products");
  27. $langs->load("admin");
  28. $langs->load("mails");
  29. $langs->load("other");
  30. $langs->load("errors");
  31. if (! $user->admin) accessforbidden();
  32. $substitutionarrayfortest=array(
  33. '__LOGIN__' => $user->login,
  34. '__ID__' => 'TESTIdRecord',
  35. '__EMAIL__' => 'TESTEMail',
  36. '__LASTNAME__' => 'TESTLastname',
  37. '__FIRSTNAME__' => 'TESTFirstname',
  38. '__SIGNATURE__' => (($user->signature && empty($conf->global->MAIL_DO_NOT_USE_SIGN))?$user->signature:''),
  39. //'__PERSONALIZED__' => 'TESTPersonalized' // Hiden because not used yet
  40. );
  41. complete_substitutions_array($substitutionarrayfortest, $langs);
  42. $action=GETPOST('action');
  43. $message='';
  44. /*
  45. * Actions
  46. */
  47. if ($action == 'update' && empty($_POST["cancel"]))
  48. {
  49. dolibarr_set_const($db, "MAIN_DISABLE_ALL_MAILS", GETPOST("MAIN_DISABLE_ALL_MAILS"),'chaine',0,'',$conf->entity);
  50. // Send mode parameters
  51. dolibarr_set_const($db, "MAIN_MAIL_SENDMODE", GETPOST("MAIN_MAIL_SENDMODE"),'chaine',0,'',0);
  52. if (isset($_POST["MAIN_MAIL_SMTP_PORT"])) dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT", GETPOST("MAIN_MAIL_SMTP_PORT"),'chaine',0,'',0);
  53. if (isset($_POST["MAIN_MAIL_SMTP_SERVER"])) dolibarr_set_const($db, "MAIN_MAIL_SMTP_SERVER", GETPOST("MAIN_MAIL_SMTP_SERVER"),'chaine',0,'',0);
  54. if (isset($_POST["MAIN_MAIL_SMTPS_ID"])) dolibarr_set_const($db, "MAIN_MAIL_SMTPS_ID", GETPOST("MAIN_MAIL_SMTPS_ID"), 'chaine',0,'',0);
  55. if (isset($_POST["MAIN_MAIL_SMTPS_PW"])) dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW", GETPOST("MAIN_MAIL_SMTPS_PW"), 'chaine',0,'',0);
  56. if (isset($_POST["MAIN_MAIL_EMAIL_TLS"])) dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS", GETPOST("MAIN_MAIL_EMAIL_TLS"),'chaine',0,'',0);
  57. // Content parameters
  58. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_FROM", GETPOST("MAIN_MAIL_EMAIL_FROM"), 'chaine',0,'',$conf->entity);
  59. dolibarr_set_const($db, "MAIN_MAIL_ERRORS_TO", GETPOST("MAIN_MAIL_ERRORS_TO"), 'chaine',0,'',$conf->entity);
  60. dolibarr_set_const($db, "MAIN_MAIL_AUTOCOPY_TO", GETPOST("MAIN_MAIL_AUTOCOPY_TO"),'chaine',0,'',$conf->entity);
  61. header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
  62. exit;
  63. }
  64. /*
  65. * Add file in email form
  66. */
  67. if (GETPOST('addfile') || GETPOST('addfilehtml'))
  68. {
  69. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  70. // Set tmp user directory
  71. $vardir=$conf->user->dir_output."/".$user->id;
  72. $upload_dir = $vardir.'/temp';
  73. dol_add_file_process($upload_dir,0,0);
  74. if ($_POST['addfile']) $action='test';
  75. if ($_POST['addfilehtml']) $action='testhtml';
  76. }
  77. /*
  78. * Remove file in email form
  79. */
  80. if (! empty($_POST['removedfile']) || ! empty($_POST['removedfilehtml']))
  81. {
  82. // Set tmp user directory
  83. $vardir=$conf->user->dir_output."/".$user->id;
  84. $upload_dir = $vardir.'/temp';
  85. $keytodelete=isset($_POST['removedfile'])?$_POST['removedfile']:$_POST['removedfilehtml'];
  86. $keytodelete--;
  87. $listofpaths=array();
  88. $listofnames=array();
  89. $listofmimes=array();
  90. if (! empty($_SESSION["listofpaths"])) $listofpaths=explode(';',$_SESSION["listofpaths"]);
  91. if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]);
  92. if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]);
  93. if ($keytodelete >= 0)
  94. {
  95. $pathtodelete=$listofpaths[$keytodelete];
  96. $filetodelete=$listofnames[$keytodelete];
  97. $result = dol_delete_file($pathtodelete,1);
  98. if ($result >= 0)
  99. {
  100. setEventMessage($langs->trans("FileWasRemoved"), $filetodelete);
  101. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  102. $formmail = new FormMail($db);
  103. $formmail->remove_attached_files($keytodelete);
  104. }
  105. }
  106. if ($_POST['removedfile'] || $action='send') $action='test';
  107. if ($_POST['removedfilehtml'] || $action='sendhtml') $action='testhtml';
  108. }
  109. /*
  110. * Cancel
  111. */
  112. if (($action == 'send' || $action == 'sendhtml') && GETPOST('cancel'))
  113. {
  114. $message='';
  115. }
  116. /*
  117. * Send mail
  118. */
  119. if (($action == 'send' || $action == 'sendhtml') && ! GETPOST('addfile') && ! GETPOST('addfilehtml') && ! GETPOST('removedfile') && ! GETPOST('cancel'))
  120. {
  121. $error=0;
  122. $email_from='';
  123. if (! empty($_POST["fromname"])) $email_from=$_POST["fromname"].' ';
  124. if (! empty($_POST["frommail"])) $email_from.='<'.$_POST["frommail"].'>';
  125. $errors_to = $_POST["errorstomail"];
  126. $sendto = $_POST["sendto"];
  127. $sendtocc = $_POST["sendtocc"];
  128. $sendtoccc = $_POST["sendtoccc"];
  129. $subject = $_POST['subject'];
  130. $body = $_POST['message'];
  131. $deliveryreceipt= $_POST["deliveryreceipt"];
  132. // Create form object
  133. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  134. $formmail = new FormMail($db);
  135. $attachedfiles=$formmail->get_attached_files();
  136. $filepath = $attachedfiles['paths'];
  137. $filename = $attachedfiles['names'];
  138. $mimetype = $attachedfiles['mimes'];
  139. if (empty($_POST["frommail"]))
  140. {
  141. $message='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("MailFrom")).'</div>';
  142. $action='test';
  143. $error++;
  144. }
  145. if (empty($sendto))
  146. {
  147. $message='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTo")).'</div>';
  148. $action='test';
  149. $error++;
  150. }
  151. if (! $error)
  152. {
  153. // Le message est-il en html
  154. $msgishtml=0; // Message is not HTML
  155. if ($action == 'sendhtml') $msgishtml=1; // Force message to HTML
  156. // Pratique les substitutions sur le sujet et message
  157. $subject=make_substitutions($subject,$substitutionarrayfortest);
  158. $body=make_substitutions($body,$substitutionarrayfortest);
  159. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  160. $mailfile = new CMailFile(
  161. $subject,
  162. $sendto,
  163. $email_from,
  164. $body,
  165. $filepath,
  166. $mimetype,
  167. $filename,
  168. $sendtocc,
  169. $sendtoccc,
  170. $deliveryreceipt,
  171. $msgishtml,
  172. $errors_to
  173. );
  174. $result=$mailfile->sendfile();
  175. if ($result)
  176. {
  177. $message='<div class="ok">'.$langs->trans("MailSuccessfulySent",$mailfile->getValidAddress($email_from,2),$mailfile->getValidAddress($sendto,2)).'</div>';
  178. }
  179. else
  180. {
  181. $message='<div class="error">'.$langs->trans("ResultKo").'<br>'.$mailfile->error.' '.$result.'</div>';
  182. }
  183. $action='';
  184. }
  185. }
  186. /*
  187. * View
  188. */
  189. $linuxlike=1;
  190. if (preg_match('/^win/i',PHP_OS)) $linuxlike=0;
  191. if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0;
  192. if (empty($conf->global->MAIN_MAIL_SENDMODE)) $conf->global->MAIN_MAIL_SENDMODE='mail';
  193. $port=! empty($conf->global->MAIN_MAIL_SMTP_PORT)?$conf->global->MAIN_MAIL_SMTP_PORT:ini_get('smtp_port');
  194. if (! $port) $port=25;
  195. $server=! empty($conf->global->MAIN_MAIL_SMTP_SERVER)?$conf->global->MAIN_MAIL_SMTP_SERVER:ini_get('SMTP');
  196. if (! $server) $server='127.0.0.1';
  197. /*
  198. * View
  199. */
  200. $wikihelp='EN:Setup EMails|FR:Paramétrage EMails|ES:Configuración EMails';
  201. llxHeader('',$langs->trans("Setup"),$wikihelp);
  202. print_fiche_titre($langs->trans("EMailsSetup"),'','setup');
  203. print $langs->trans("EMailsDesc")."<br>\n";
  204. print "<br>\n";
  205. dol_htmloutput_mesg($message);
  206. // List of sending methods
  207. $listofmethods=array();
  208. $listofmethods['mail']='PHP mail function';
  209. //$listofmethods['simplemail']='Simplemail class';
  210. $listofmethods['smtps']='SMTP/SMTPS socket library';
  211. if ($action == 'edit')
  212. {
  213. $form=new Form($db);
  214. if ($conf->use_javascript_ajax)
  215. {
  216. print "\n".'<script type="text/javascript" language="javascript">';
  217. print 'jQuery(document).ready(function () {
  218. function initfields()
  219. {
  220. if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'mail\')
  221. {
  222. jQuery(".drag").hide();
  223. jQuery("#MAIN_MAIL_EMAIL_TLS").val(0);
  224. jQuery("#MAIN_MAIL_EMAIL_TLS").attr(\'disabled\', \'disabled\');
  225. ';
  226. if ($linuxlike)
  227. {
  228. print ' jQuery("#MAIN_MAIL_SMTP_SERVER").attr(\'disabled\', \'disabled\');';
  229. print ' jQuery("#MAIN_MAIL_SMTP_PORT").attr(\'disabled\', \'disabled\');';
  230. }
  231. print '
  232. }
  233. if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'smtps\')
  234. {
  235. jQuery(".drag").show();
  236. jQuery("#MAIN_MAIL_EMAIL_TLS").val('.$conf->global->MAIN_MAIL_EMAIL_TLS.');
  237. jQuery("#MAIN_MAIL_EMAIL_TLS").removeAttr(\'disabled\');
  238. jQuery("#MAIN_MAIL_SMTP_SERVER").removeAttr(\'disabled\');
  239. jQuery("#MAIN_MAIL_SMTP_PORT").removeAttr(\'disabled\');
  240. }
  241. }
  242. initfields();
  243. jQuery("#MAIN_MAIL_SENDMODE").change(function() {
  244. initfields();
  245. });
  246. })';
  247. print '</script>'."\n";
  248. }
  249. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  250. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  251. print '<input type="hidden" name="action" value="update">';
  252. clearstatcache();
  253. $var=true;
  254. print '<table class="noborder" width="100%">';
  255. print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  256. // Disable
  257. $var=!$var;
  258. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_DISABLE_ALL_MAILS").'</td><td>';
  259. print $form->selectyesno('MAIN_DISABLE_ALL_MAILS',$conf->global->MAIN_DISABLE_ALL_MAILS,1);
  260. print '</td></tr>';
  261. // Separator
  262. $var=!$var;
  263. print '<tr '.$bc[$var].'><td colspan="2">&nbsp;</td></tr>';
  264. // Method
  265. $var=!$var;
  266. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
  267. // SuperAdministrator access only
  268. if ((empty($conf->global->MAIN_MODULE_MULTICOMPANY)) || ($user->admin && !$user->entity))
  269. {
  270. print $form->selectarray('MAIN_MAIL_SENDMODE',$listofmethods,$conf->global->MAIN_MAIL_SENDMODE);
  271. }
  272. else
  273. {
  274. $text = $listofmethods[$conf->global->MAIN_MAIL_SENDMODE];
  275. if (empty($text)) $text = $langs->trans("Undefined");
  276. $htmltext = $langs->trans("ContactSuperAdminForChange");
  277. print $form->textwithpicto($text,$htmltext,1,'superadmin');
  278. print '<input type="hidden" name="MAIN_MAIL_SENDMODE" value="'.$conf->global->MAIN_MAIL_SENDMODE.'">';
  279. }
  280. print '</td></tr>';
  281. // Server
  282. $var=!$var;
  283. print '<tr '.$bc[$var].'><td>';
  284. if (! $conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE == 'mail')
  285. {
  286. print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
  287. print '</td><td>';
  288. print $langs->trans("SeeLocalSendMailSetup");
  289. }
  290. else
  291. {
  292. $mainserver = (! empty($conf->global->MAIN_MAIL_SMTP_SERVER)?$conf->global->MAIN_MAIL_SMTP_SERVER:'');
  293. $smtpserver = ini_get('SMTP')?ini_get('SMTP'):$langs->transnoentities("Undefined");
  294. if ($linuxlike) print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
  295. else print $langs->trans("MAIN_MAIL_SMTP_SERVER",$smtpserver);
  296. print '</td><td>';
  297. // SuperAdministrator access only
  298. if (empty($conf->multicompany->enabled) || ($user->admin && ! $user->entity))
  299. {
  300. print '<input class="flat" id="MAIN_MAIL_SMTP_SERVER" name="MAIN_MAIL_SMTP_SERVER" size="18" value="' . $mainserver . '">';
  301. print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_sav" name="MAIN_MAIL_SMTP_SERVER_sav" value="' . $mainserver . '">';
  302. }
  303. else
  304. {
  305. $text = ! empty($mainserver) ? $mainserver : $smtpserver;
  306. $htmltext = $langs->trans("ContactSuperAdminForChange");
  307. print $form->textwithpicto($text,$htmltext,1,'superadmin');
  308. print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER" name="MAIN_MAIL_SMTP_SERVER" value="'.$mainserver.'">';
  309. }
  310. }
  311. print '</td></tr>';
  312. // Port
  313. $var=!$var;
  314. print '<tr '.$bc[$var].'><td>';
  315. if (! $conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE == 'mail')
  316. {
  317. print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
  318. print '</td><td>';
  319. print $langs->trans("SeeLocalSendMailSetup");
  320. }
  321. else
  322. {
  323. $mainport = (! empty($conf->global->MAIN_MAIL_SMTP_PORT) ? $conf->global->MAIN_MAIL_SMTP_PORT : '');
  324. $smtpport = ini_get('smtp_port')?ini_get('smtp_port'):$langs->transnoentities("Undefined");
  325. if ($linuxlike) print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
  326. else print $langs->trans("MAIN_MAIL_SMTP_PORT",$smtpport);
  327. print '</td><td>';
  328. // SuperAdministrator access only
  329. if (empty($conf->multicompany->enabled) || ($user->admin && ! $user->entity))
  330. {
  331. print '<input class="flat" id="MAIN_MAIL_SMTP_PORT" name="MAIN_MAIL_SMTP_PORT" size="3" value="' . $mainport . '">';
  332. print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_sav" name="MAIN_MAIL_SMTP_PORT_sav" value="' . $mainport . '">';
  333. }
  334. else
  335. {
  336. $text = (! empty($mainport) ? $mainport : $smtpport);
  337. $htmltext = $langs->trans("ContactSuperAdminForChange");
  338. print $form->textwithpicto($text,$htmltext,1,'superadmin');
  339. print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT" name="MAIN_MAIL_SMTP_PORT" value="'.$mainport.'">';
  340. }
  341. }
  342. print '</td></tr>';
  343. // ID
  344. if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'smtps'))
  345. {
  346. $var=!$var;
  347. $mainstmpid=(! empty($conf->global->MAIN_MAIL_SMTPS_ID)?$conf->global->MAIN_MAIL_SMTPS_ID:'');
  348. print '<tr '.$bcdd[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>';
  349. // SuperAdministrator access only
  350. if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity))
  351. {
  352. print '<input class="flat" name="MAIN_MAIL_SMTPS_ID" size="32" value="' . $mainstmpid . '">';
  353. }
  354. else
  355. {
  356. $htmltext = $langs->trans("ContactSuperAdminForChange");
  357. print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_ID,$htmltext,1,'superadmin');
  358. print '<input type="hidden" name="MAIN_MAIL_SMTPS_ID" value="'.$mainstmpid.'">';
  359. }
  360. print '</td></tr>';
  361. }
  362. // PW
  363. if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'smtps'))
  364. {
  365. $var=!$var;
  366. $mainsmtppw=(! empty($conf->global->MAIN_MAIL_SMTPS_PW)?$conf->global->MAIN_MAIL_SMTPS_PW:'');
  367. print '<tr '.$bcdd[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>';
  368. // SuperAdministrator access only
  369. if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity))
  370. {
  371. print '<input class="flat" name="MAIN_MAIL_SMTPS_PW" size="32" value="' . $mainsmtppw . '">';
  372. }
  373. else
  374. {
  375. $htmltext = $langs->trans("ContactSuperAdminForChange");
  376. print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_PW,$htmltext,1,'superadmin');
  377. print '<input type="hidden" name="MAIN_MAIL_SMTPS_PW" value="'.$mainsmtppw.'">';
  378. }
  379. print '</td></tr>';
  380. }
  381. // TLS
  382. $var=!$var;
  383. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
  384. if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'smtps'))
  385. {
  386. if (function_exists('openssl_open'))
  387. {
  388. print $form->selectyesno('MAIN_MAIL_EMAIL_TLS',(! empty($conf->global->MAIN_MAIL_EMAIL_TLS)?$conf->global->MAIN_MAIL_EMAIL_TLS:0),1);
  389. }
  390. else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  391. }
  392. else print yn(0).' ('.$langs->trans("NotSupported").')';
  393. print '</td></tr>';
  394. // Separator
  395. $var=!$var;
  396. print '<tr '.$bc[$var].'><td colspan="2">&nbsp;</td></tr>';
  397. // From
  398. $var=!$var;
  399. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_EMAIL_FROM",ini_get('sendmail_from')?ini_get('sendmail_from'):$langs->transnoentities("Undefined")).'</td>';
  400. 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:'');
  401. print '"></td></tr>';
  402. // From
  403. $var=!$var;
  404. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_ERRORS_TO").'</td>';
  405. 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:'');
  406. print '"></td></tr>';
  407. // Autocopy to
  408. $var=!$var;
  409. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
  410. 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:'');
  411. print '"></td></tr>';
  412. print '</table>';
  413. print '<br><center>';
  414. print '<input class="button" type="submit" name="save" value="'.$langs->trans("Save").'">';
  415. print ' &nbsp; &nbsp; ';
  416. print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  417. print '</center>';
  418. print '</form>';
  419. print '<br>';
  420. }
  421. else
  422. {
  423. $var=true;
  424. print '<table class="noborder" width="100%">';
  425. print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  426. // Disable
  427. $var=!$var;
  428. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_DISABLE_ALL_MAILS").'</td><td>'.yn($conf->global->MAIN_DISABLE_ALL_MAILS).'</td></tr>';
  429. // Separator
  430. $var=!$var;
  431. print '<tr '.$bc[$var].'><td colspan="2">&nbsp;</td></tr>';
  432. // Method
  433. $var=!$var;
  434. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
  435. $text=$listofmethods[$conf->global->MAIN_MAIL_SENDMODE];
  436. if (empty($text)) $text=$langs->trans("Undefined").img_warning();
  437. print $text;
  438. print '</td></tr>';
  439. // Server
  440. $var=!$var;
  441. if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'mail'))
  442. {
  443. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
  444. }
  445. else
  446. {
  447. print '<tr '.$bc[$var].'><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>';
  448. }
  449. // Port
  450. $var=!$var;
  451. if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'mail'))
  452. {
  453. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
  454. }
  455. else
  456. {
  457. print '<tr '.$bc[$var].'><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>';
  458. }
  459. // SMTPS ID
  460. $var=!$var;
  461. if (isset($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'smtps')
  462. {
  463. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>'.$conf->global->MAIN_MAIL_SMTPS_ID.'</td></tr>';
  464. }
  465. // SMTPS PW
  466. $var=!$var;
  467. if (isset($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'smtps')
  468. {
  469. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>'.preg_replace('/./','*',$conf->global->MAIN_MAIL_SMTPS_PW).'</td></tr>';
  470. }
  471. // TLS
  472. $var=!$var;
  473. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
  474. if (isset($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'smtps')
  475. {
  476. if (function_exists('openssl_open'))
  477. {
  478. print yn($conf->global->MAIN_MAIL_EMAIL_TLS);
  479. }
  480. else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  481. }
  482. else print yn(0).' ('.$langs->trans("NotSupported").')';
  483. print '</td></tr>';
  484. // Separator
  485. $var=!$var;
  486. print '<tr '.$bc[$var].'><td colspan="2">&nbsp;</td></tr>';
  487. // From
  488. $var=!$var;
  489. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_EMAIL_FROM",ini_get('sendmail_from')?ini_get('sendmail_from'):$langs->transnoentities("Undefined")).'</td>';
  490. print '<td>'.$conf->global->MAIN_MAIL_EMAIL_FROM;
  491. if (! empty($conf->global->MAIN_MAIL_EMAIL_FROM) && ! isValidEmail($conf->global->MAIN_MAIL_EMAIL_FROM)) print img_warning($langs->trans("ErrorBadEMail"));
  492. print '</td></tr>';
  493. // Errors To
  494. $var=!$var;
  495. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_ERRORS_TO").'</td>';
  496. print '<td>'.$conf->global->MAIN_MAIL_ERRORS_TO;
  497. if (! empty($conf->global->MAIN_MAIL_ERRORS_TO) && ! isValidEmail($conf->global->MAIN_MAIL_ERRORS_TO)) print img_warning($langs->trans("ErrorBadEMail"));
  498. print '</td></tr>';
  499. // Autocopy to
  500. $var=!$var;
  501. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
  502. print '<td>';
  503. if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_TO))
  504. {
  505. print $conf->global->MAIN_MAIL_AUTOCOPY_TO;
  506. if (! isValidEmail($conf->global->MAIN_MAIL_AUTOCOPY_TO)) print img_warning($langs->trans("ErrorBadEMail"));
  507. }
  508. else
  509. {
  510. print '&nbsp;';
  511. }
  512. print '</td></tr>';
  513. print '</table>';
  514. // Warning 1
  515. if ($conf->global->MAIN_MAIL_SENDMODE == 'mail')
  516. {
  517. print '<br>';
  518. if ($linuxlike)
  519. {
  520. $sendmailoption=ini_get('mail.force_extra_parameters');
  521. //print 'x'.$sendmailoption;
  522. if (empty($sendmailoption) || ! preg_match('/ba/',$sendmailoption))
  523. {
  524. print info_admin($langs->trans("SendmailOptionNotComplete"));
  525. }
  526. }
  527. // Warning 2
  528. print info_admin($langs->trans("SendmailOptionMayHurtBuggedMTA"));
  529. }
  530. // Boutons actions
  531. print '<div class="tabsAction">';
  532. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
  533. if ($conf->global->MAIN_MAIL_SENDMODE != 'mail' || ! $linuxlike)
  534. {
  535. if (function_exists('fsockopen') && $port && $server)
  536. {
  537. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
  538. }
  539. }
  540. else
  541. {
  542. print '<a class="butActionRefused" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
  543. }
  544. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&amp;mode=init">'.$langs->trans("DoTestSend").'</a>';
  545. if (! empty($conf->fckeditor->enabled))
  546. {
  547. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testhtml&amp;mode=init">'.$langs->trans("DoTestSendHTML").'</a>';
  548. }
  549. print '</div>';
  550. // Run the test to connect
  551. if ($action == 'testconnect')
  552. {
  553. print '<br>';
  554. print_titre($langs->trans("DoTestServerAvailability"));
  555. // If we use SSL/TLS
  556. if (! empty($conf->global->MAIN_MAIL_EMAIL_TLS) && function_exists('openssl_open')) $server='ssl://'.$server;
  557. include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  558. $mail = new CMailFile('','','','');
  559. $result=$mail->check_server_port($server,$port);
  560. if ($result) print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort",$server,$port).'</div>';
  561. else
  562. {
  563. print '<div class="error">'.$langs->trans("ServerNotAvailableOnIPOrPort",$server,$port);
  564. if ($mail->error) print ' - '.$mail->error;
  565. print '</div>';
  566. }
  567. print '<br>';
  568. }
  569. // Affichage formulaire de TEST simple
  570. if ($action == 'test')
  571. {
  572. print '<br>';
  573. print_titre($langs->trans("DoTestSend"));
  574. // Cree l'objet formulaire mail
  575. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  576. $formmail = new FormMail($db);
  577. $formmail->fromname = (isset($_POST['fromname'])?$_POST['fromname']:$conf->global->MAIN_MAIL_EMAIL_FROM);
  578. $formmail->frommail = (isset($_POST['frommail'])?$_POST['frommail']:$conf->global->MAIN_MAIL_EMAIL_FROM);
  579. $formmail->withfromreadonly=0;
  580. $formmail->withsubstit=0;
  581. $formmail->withfrom=1;
  582. $formmail->witherrorsto=1;
  583. $formmail->withto=(! empty($_POST['sendto'])?$_POST['sendto']:($user->email?$user->email:1));
  584. $formmail->withtocc=(! empty($_POST['sendtocc'])?$_POST['sendtocc']:1); // ! empty to keep field if empty
  585. $formmail->withtoccc=(! empty($_POST['sendtoccc'])?$_POST['sendtoccc']:1); // ! empty to keep field if empty
  586. $formmail->withtopic=(isset($_POST['subject'])?$_POST['subject']:$langs->trans("Test"));
  587. $formmail->withtopicreadonly=0;
  588. $formmail->withfile=2;
  589. $formmail->withbody=(isset($_POST['message'])?$_POST['message']:$langs->trans("PredefinedMailTest"));
  590. $formmail->withbodyreadonly=0;
  591. $formmail->withcancel=1;
  592. $formmail->withdeliveryreceipt=1;
  593. $formmail->withfckeditor=0;
  594. // Tableau des substitutions
  595. $formmail->substit=$substitutionarrayfortest;
  596. // Tableau des parametres complementaires du post
  597. $formmail->param["action"]="send";
  598. $formmail->param["models"]="body";
  599. $formmail->param["mailid"]=0;
  600. $formmail->param["returnurl"]=$_SERVER["PHP_SELF"];
  601. // Init list of files
  602. if (GETPOST("mode")=='init')
  603. {
  604. $formmail->clear_attached_files();
  605. }
  606. $formmail->show_form('addfile','removefile');
  607. print '<br>';
  608. }
  609. // Affichage formulaire de TEST HTML
  610. if ($action == 'testhtml')
  611. {
  612. print '<br>';
  613. print_titre($langs->trans("DoTestSendHTML"));
  614. // Cree l'objet formulaire mail
  615. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  616. $formmail = new FormMail($db);
  617. $formmail->fromname = (isset($_POST['fromname'])?$_POST['fromname']:$conf->global->MAIN_MAIL_EMAIL_FROM);
  618. $formmail->frommail = (isset($_POST['frommail'])?$_POST['frommail']:$conf->global->MAIN_MAIL_EMAIL_FROM);
  619. $formmail->withfromreadonly=0;
  620. $formmail->withsubstit=0;
  621. $formmail->withfrom=1;
  622. $formmail->witherrorsto=1;
  623. $formmail->withto=(! empty($_POST['sendto'])?$_POST['sendto']:($user->email?$user->email:1));
  624. $formmail->withtocc=(! empty($_POST['sendtocc'])?$_POST['sendtocc']:1); // ! empty to keep field if empty
  625. $formmail->withtoccc=(! empty($_POST['sendtoccc'])?$_POST['sendtoccc']:1); // ! empty to keep field if empty
  626. $formmail->withtopic=(isset($_POST['subject'])?$_POST['subject']:$langs->trans("Test"));
  627. $formmail->withtopicreadonly=0;
  628. $formmail->withfile=2;
  629. $formmail->withbody=(isset($_POST['message'])?$_POST['message']:$langs->trans("PredefinedMailTestHtml"));
  630. //$formmail->withbody='Test <b>aaa</b> __LOGIN__';
  631. $formmail->withbodyreadonly=0;
  632. $formmail->withcancel=1;
  633. $formmail->withdeliveryreceipt=1;
  634. $formmail->withfckeditor=1;
  635. $formmail->ckeditortoolbar='dolibarr_mailings';
  636. // Tableau des substitutions
  637. $formmail->substit=$substitutionarrayfortest;
  638. // Tableau des parametres complementaires du post
  639. $formmail->param["action"]="sendhtml";
  640. $formmail->param["models"]="body";
  641. $formmail->param["mailid"]=0;
  642. $formmail->param["returnurl"]=$_SERVER["PHP_SELF"];
  643. // Init list of files
  644. if (GETPOST("mode")=='init')
  645. {
  646. $formmail->clear_attached_files();
  647. }
  648. $formmail->show_form('addfilehtml','removefilehtml');
  649. print '<br>';
  650. }
  651. }
  652. llxFooter();
  653. $db->close();
  654. ?>