mails.php 26 KB

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