mails.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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. /**
  21. * \file htdocs/admin/mails.php
  22. * \brief Page to setup emails sending
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  27. $langs->load("companies");
  28. $langs->load("products");
  29. $langs->load("admin");
  30. $langs->load("mails");
  31. $langs->load("other");
  32. $langs->load("errors");
  33. $action=GETPOST('action','alpha');
  34. if (! $user->admin) accessforbidden();
  35. $usersignature=$user->signature;
  36. // For action = test or send, we ensure that content is not html, even for signature, because this we want a test with NO html.
  37. if ($action == 'test' || $action == 'send')
  38. {
  39. $usersignature=dol_string_nohtmltag($usersignature);
  40. }
  41. $substitutionarrayfortest=array(
  42. '__LOGIN__' => $user->login,
  43. '__ID__' => 'TESTIdRecord',
  44. '__EMAIL__' => 'TESTEMail',
  45. '__LASTNAME__' => 'TESTLastname',
  46. '__FIRSTNAME__' => 'TESTFirstname',
  47. '__SIGNATURE__' => (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))?$usersignature:''),
  48. //'__PERSONALIZED__' => 'TESTPersonalized' // Hiden because not used yet
  49. );
  50. complete_substitutions_array($substitutionarrayfortest, $langs);
  51. /*
  52. * Actions
  53. */
  54. if ($action == 'update' && empty($_POST["cancel"]))
  55. {
  56. dolibarr_set_const($db, "MAIN_DISABLE_ALL_MAILS", GETPOST("MAIN_DISABLE_ALL_MAILS"),'chaine',0,'',$conf->entity);
  57. // Send mode parameters
  58. dolibarr_set_const($db, "MAIN_MAIL_SENDMODE", GETPOST("MAIN_MAIL_SENDMODE"),'chaine',0,'',$conf->entity);
  59. dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT", GETPOST("MAIN_MAIL_SMTP_PORT"),'chaine',0,'',$conf->entity);
  60. dolibarr_set_const($db, "MAIN_MAIL_SMTP_SERVER", GETPOST("MAIN_MAIL_SMTP_SERVER"),'chaine',0,'',$conf->entity);
  61. dolibarr_set_const($db, "MAIN_MAIL_SMTPS_ID", GETPOST("MAIN_MAIL_SMTPS_ID"), 'chaine',0,'',$conf->entity);
  62. dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW", GETPOST("MAIN_MAIL_SMTPS_PW"), 'chaine',0,'',$conf->entity);
  63. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS", GETPOST("MAIN_MAIL_EMAIL_TLS"),'chaine',0,'',$conf->entity);
  64. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS", GETPOST("MAIN_MAIL_EMAIL_STARTTLS"),'chaine',0,'',$conf->entity);
  65. // Content parameters
  66. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_FROM", GETPOST("MAIN_MAIL_EMAIL_FROM"), 'chaine',0,'',$conf->entity);
  67. dolibarr_set_const($db, "MAIN_MAIL_ERRORS_TO", GETPOST("MAIN_MAIL_ERRORS_TO"), 'chaine',0,'',$conf->entity);
  68. dolibarr_set_const($db, "MAIN_MAIL_AUTOCOPY_TO", GETPOST("MAIN_MAIL_AUTOCOPY_TO"),'chaine',0,'',$conf->entity);
  69. dolibarr_set_const($db, 'MAIN_MAIL_DEFAULT_FROMTYPE',GETPOST('MAIN_MAIL_DEFAULT_FROMTYPE'),'chaine',0,'',$conf->entity);
  70. header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
  71. exit;
  72. }
  73. // Actions to send emails
  74. $id=0;
  75. $actiontypecode=''; // Not an event for agenda
  76. $trigger_name=''; // Disable triggers
  77. $paramname='id';
  78. $mode='emailfortest';
  79. $trackid=(($action == 'testhtml')?"testhtml":"test");
  80. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  81. if ($action == 'presend' && GETPOST('trackid') == 'test') $action='test';
  82. if ($action == 'presend' && GETPOST('trackid') == 'testhtml') $action='testhtml';
  83. /*
  84. * View
  85. */
  86. $linuxlike=1;
  87. if (preg_match('/^win/i',PHP_OS)) $linuxlike=0;
  88. if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0;
  89. if (empty($conf->global->MAIN_MAIL_SENDMODE)) $conf->global->MAIN_MAIL_SENDMODE='mail';
  90. $port=! empty($conf->global->MAIN_MAIL_SMTP_PORT)?$conf->global->MAIN_MAIL_SMTP_PORT:ini_get('smtp_port');
  91. if (! $port) $port=25;
  92. $server=! empty($conf->global->MAIN_MAIL_SMTP_SERVER)?$conf->global->MAIN_MAIL_SMTP_SERVER:ini_get('SMTP');
  93. if (! $server) $server='127.0.0.1';
  94. $wikihelp='EN:Setup EMails|FR:Paramétrage EMails|ES:Configuración EMails';
  95. llxHeader('',$langs->trans("Setup"),$wikihelp);
  96. print load_fiche_titre($langs->trans("EMailsSetup"),'','title_setup');
  97. $h = 0;
  98. $head[$h][0] = DOL_URL_ROOT."/admin/mails.php";
  99. $head[$h][1] = $langs->trans("OutGoingEmailSetup");
  100. $head[$h][2] = 'common';
  101. $h++;
  102. $head[$h][0] = DOL_URL_ROOT."/admin/mails_templates.php";
  103. $head[$h][1] = $langs->trans("DictionaryEMailTemplates");
  104. $head[$h][2] = 'templates';
  105. $h++;
  106. // List of sending methods
  107. $listofmethods=array();
  108. $listofmethods['mail']='PHP mail function';
  109. //$listofmethods['simplemail']='Simplemail class';
  110. $listofmethods['smtps']='SMTP/SMTPS socket library';
  111. $listofmethods['swiftmailer']='Swift Mailer socket library';
  112. if ($action == 'edit')
  113. {
  114. $form=new Form($db);
  115. if ($conf->use_javascript_ajax)
  116. {
  117. print "\n".'<script type="text/javascript" language="javascript">';
  118. print 'jQuery(document).ready(function () {
  119. function initfields()
  120. {
  121. if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'mail\')
  122. {
  123. jQuery(".drag").hide();
  124. jQuery("#MAIN_MAIL_EMAIL_TLS").val(0);
  125. jQuery("#MAIN_MAIL_EMAIL_TLS").prop("disabled", true);
  126. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val(0);
  127. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").prop("disabled", true);
  128. ';
  129. if ($linuxlike)
  130. {
  131. print '
  132. jQuery("#MAIN_MAIL_SMTP_SERVER").hide();
  133. jQuery("#MAIN_MAIL_SMTP_PORT").hide();
  134. jQuery("#smtp_server_mess").show();
  135. jQuery("#smtp_port_mess").show();
  136. ';
  137. }
  138. else
  139. {
  140. print '
  141. jQuery("#MAIN_MAIL_SMTP_SERVER").prop("disabled", true);
  142. jQuery("#MAIN_MAIL_SMTP_PORT").prop("disabled", true);
  143. jQuery("#smtp_server_mess").hide();
  144. jQuery("#smtp_port_mess").hide();
  145. ';
  146. }
  147. print '
  148. }
  149. if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'smtps\')
  150. {
  151. jQuery(".drag").show();
  152. jQuery("#MAIN_MAIL_EMAIL_TLS").val('.$conf->global->MAIN_MAIL_EMAIL_TLS.');
  153. jQuery("#MAIN_MAIL_EMAIL_TLS").removeAttr("disabled");
  154. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS.');
  155. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").removeAttr("disabled");
  156. jQuery("#MAIN_MAIL_SMTP_SERVER").removeAttr("disabled");
  157. jQuery("#MAIN_MAIL_SMTP_PORT").removeAttr("disabled");
  158. jQuery("#MAIN_MAIL_SMTP_SERVER").show();
  159. jQuery("#MAIN_MAIL_SMTP_PORT").show();
  160. jQuery("#smtp_server_mess").hide();
  161. jQuery("#smtp_port_mess").hide();
  162. }
  163. if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'swiftmailer\')
  164. {
  165. jQuery(".drag").show();
  166. jQuery("#MAIN_MAIL_EMAIL_TLS").val('.$conf->global->MAIN_MAIL_EMAIL_TLS.');
  167. jQuery("#MAIN_MAIL_EMAIL_TLS").removeAttr("disabled");
  168. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS.');
  169. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").removeAttr("disabled");
  170. jQuery("#MAIN_MAIL_SMTP_SERVER").removeAttr("disabled");
  171. jQuery("#MAIN_MAIL_SMTP_PORT").removeAttr("disabled");
  172. jQuery("#MAIN_MAIL_SMTP_SERVER").show();
  173. jQuery("#MAIN_MAIL_SMTP_PORT").show();
  174. jQuery("#smtp_server_mess").hide();
  175. jQuery("#smtp_port_mess").hide();
  176. }
  177. }
  178. initfields();
  179. jQuery("#MAIN_MAIL_SENDMODE").change(function() {
  180. initfields();
  181. });
  182. jQuery("#MAIN_MAIL_EMAIL_TLS").change(function() {
  183. if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val() == 1)
  184. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val(0);
  185. });
  186. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").change(function() {
  187. if (jQuery("#MAIN_MAIL_EMAIL_TLS").val() == 1)
  188. jQuery("#MAIN_MAIL_EMAIL_TLS").val(0);
  189. });
  190. })';
  191. print '</script>'."\n";
  192. }
  193. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  194. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  195. print '<input type="hidden" name="action" value="update">';
  196. dol_fiche_head($head, 'common', '', -1);
  197. print $langs->trans("EMailsDesc")."<br>\n";
  198. print "<br>\n";
  199. clearstatcache();
  200. $var=true;
  201. print '<table class="noborder" width="100%">';
  202. print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  203. // Disable
  204. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_MAILS").'</td><td>';
  205. print $form->selectyesno('MAIN_DISABLE_ALL_MAILS',$conf->global->MAIN_DISABLE_ALL_MAILS,1);
  206. print '</td></tr>';
  207. // Separator
  208. print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
  209. // Method
  210. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
  211. // SuperAdministrator access only
  212. if ((empty($conf->global->MAIN_MODULE_MULTICOMPANY)) || ($user->admin && !$user->entity))
  213. {
  214. print $form->selectarray('MAIN_MAIL_SENDMODE',$listofmethods,$conf->global->MAIN_MAIL_SENDMODE);
  215. }
  216. else
  217. {
  218. $text = $listofmethods[$conf->global->MAIN_MAIL_SENDMODE];
  219. if (empty($text)) $text = $langs->trans("Undefined");
  220. $htmltext = $langs->trans("ContactSuperAdminForChange");
  221. print $form->textwithpicto($text,$htmltext,1,'superadmin');
  222. print '<input type="hidden" name="MAIN_MAIL_SENDMODE" value="'.$conf->global->MAIN_MAIL_SENDMODE.'">';
  223. }
  224. print '</td></tr>';
  225. // Host server
  226. print '<tr class="oddeven"><td>';
  227. if (! $conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE == 'mail')
  228. {
  229. print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
  230. print '</td><td>';
  231. print $langs->trans("SeeLocalSendMailSetup");
  232. }
  233. else
  234. {
  235. $mainserver = (! empty($conf->global->MAIN_MAIL_SMTP_SERVER)?$conf->global->MAIN_MAIL_SMTP_SERVER:'');
  236. $smtpserver = ini_get('SMTP')?ini_get('SMTP'):$langs->transnoentities("Undefined");
  237. if ($linuxlike) print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
  238. else print $langs->trans("MAIN_MAIL_SMTP_SERVER",$smtpserver);
  239. print '</td><td>';
  240. // SuperAdministrator access only
  241. if (empty($conf->multicompany->enabled) || ($user->admin && ! $user->entity))
  242. {
  243. print '<input class="flat" id="MAIN_MAIL_SMTP_SERVER" name="MAIN_MAIL_SMTP_SERVER" size="18" value="' . $mainserver . '">';
  244. print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_sav" name="MAIN_MAIL_SMTP_SERVER_sav" value="' . $mainserver . '">';
  245. print '<span id="smtp_server_mess">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
  246. }
  247. else
  248. {
  249. $text = ! empty($mainserver) ? $mainserver : $smtpserver;
  250. $htmltext = $langs->trans("ContactSuperAdminForChange");
  251. print $form->textwithpicto($text,$htmltext,1,'superadmin');
  252. print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER" name="MAIN_MAIL_SMTP_SERVER" value="'.$mainserver.'">';
  253. }
  254. }
  255. print '</td></tr>';
  256. // Port
  257. print '<tr class="oddeven"><td>';
  258. if (! $conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE == 'mail')
  259. {
  260. print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
  261. print '</td><td>';
  262. print $langs->trans("SeeLocalSendMailSetup");
  263. }
  264. else
  265. {
  266. $mainport = (! empty($conf->global->MAIN_MAIL_SMTP_PORT) ? $conf->global->MAIN_MAIL_SMTP_PORT : '');
  267. $smtpport = ini_get('smtp_port')?ini_get('smtp_port'):$langs->transnoentities("Undefined");
  268. if ($linuxlike) print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
  269. else print $langs->trans("MAIN_MAIL_SMTP_PORT",$smtpport);
  270. print '</td><td>';
  271. // SuperAdministrator access only
  272. if (empty($conf->multicompany->enabled) || ($user->admin && ! $user->entity))
  273. {
  274. print '<input class="flat" id="MAIN_MAIL_SMTP_PORT" name="MAIN_MAIL_SMTP_PORT" size="3" value="' . $mainport . '">';
  275. print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_sav" name="MAIN_MAIL_SMTP_PORT_sav" value="' . $mainport . '">';
  276. print '<span id="smtp_port_mess">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
  277. }
  278. else
  279. {
  280. $text = (! empty($mainport) ? $mainport : $smtpport);
  281. $htmltext = $langs->trans("ContactSuperAdminForChange");
  282. print $form->textwithpicto($text,$htmltext,1,'superadmin');
  283. print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT" name="MAIN_MAIL_SMTP_PORT" value="'.$mainport.'">';
  284. }
  285. }
  286. print '</td></tr>';
  287. // ID
  288. if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))))
  289. {
  290. $mainstmpid=(! empty($conf->global->MAIN_MAIL_SMTPS_ID)?$conf->global->MAIN_MAIL_SMTPS_ID:'');
  291. print '<tr '.$bcdd[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>';
  292. // SuperAdministrator access only
  293. if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity))
  294. {
  295. print '<input class="flat" name="MAIN_MAIL_SMTPS_ID" size="32" value="' . $mainstmpid . '">';
  296. }
  297. else
  298. {
  299. $htmltext = $langs->trans("ContactSuperAdminForChange");
  300. print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_ID,$htmltext,1,'superadmin');
  301. print '<input type="hidden" name="MAIN_MAIL_SMTPS_ID" value="'.$mainstmpid.'">';
  302. }
  303. print '</td></tr>';
  304. }
  305. // PW
  306. if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))))
  307. {
  308. $mainsmtppw=(! empty($conf->global->MAIN_MAIL_SMTPS_PW)?$conf->global->MAIN_MAIL_SMTPS_PW:'');
  309. print '<tr '.$bcdd[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>';
  310. // SuperAdministrator access only
  311. if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity))
  312. {
  313. print '<input class="flat" type="password" name="MAIN_MAIL_SMTPS_PW" size="32" value="' . $mainsmtppw . '">';
  314. }
  315. else
  316. {
  317. $htmltext = $langs->trans("ContactSuperAdminForChange");
  318. print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_PW,$htmltext,1,'superadmin');
  319. print '<input type="hidden" name="MAIN_MAIL_SMTPS_PW" value="'.$mainsmtppw.'">';
  320. }
  321. print '</td></tr>';
  322. }
  323. // TLS
  324. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
  325. if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))))
  326. {
  327. if (function_exists('openssl_open'))
  328. {
  329. print $form->selectyesno('MAIN_MAIL_EMAIL_TLS',(! empty($conf->global->MAIN_MAIL_EMAIL_TLS)?$conf->global->MAIN_MAIL_EMAIL_TLS:0),1);
  330. }
  331. else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  332. }
  333. else print yn(0).' ('.$langs->trans("NotSupported").')';
  334. print '</td></tr>';
  335. // STARTTLS
  336. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
  337. if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))))
  338. {
  339. if (function_exists('openssl_open'))
  340. {
  341. print $form->selectyesno('MAIN_MAIL_EMAIL_STARTTLS',(! empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS)?$conf->global->MAIN_MAIL_EMAIL_STARTTLS:0),1);
  342. }
  343. else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  344. }
  345. else print yn(0).' ('.$langs->trans("NotSupported").')';
  346. print '</td></tr>';
  347. // Separator
  348. print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
  349. // From
  350. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_FROM",ini_get('sendmail_from')?ini_get('sendmail_from'):$langs->transnoentities("Undefined")).'</td>';
  351. 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:'');
  352. print '"></td></tr>';
  353. // Default from type
  354. $liste = array();
  355. $liste['user'] = $langs->trans('UserEmail');
  356. $liste['company'] = $langs->trans('CompanyEmail').' ('.(empty($conf->global->MAIN_INFO_SOCIETE_MAIL)?$langs->trans("NotDefined"):$conf->global->MAIN_INFO_SOCIETE_MAIL).')';
  357. print '<tr '.$bc[$var?1:0].'><td>'.$langs->trans('MAIN_MAIL_DEFAULT_FROMTYPE').'</td><td>';
  358. print $form->selectarray('MAIN_MAIL_DEFAULT_FROMTYPE',$liste,$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE,0);
  359. print '</td></tr>';
  360. // Separator
  361. print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
  362. // From
  363. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ERRORS_TO").'</td>';
  364. 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:'');
  365. print '"></td></tr>';
  366. // Autocopy to
  367. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
  368. 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:'');
  369. print '"></td></tr>';
  370. print '</table>';
  371. dol_fiche_end();
  372. print '<br><div class="center">';
  373. print '<input class="button" type="submit" name="save" value="'.$langs->trans("Save").'">';
  374. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  375. print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  376. print '</div>';
  377. print '</form>';
  378. }
  379. else
  380. {
  381. dol_fiche_head($head, 'common', '', -1);
  382. print $langs->trans("EMailsDesc")."<br>\n";
  383. print "<br>\n";
  384. $var=true;
  385. print '<table class="noborder" width="100%">';
  386. print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  387. // Disable
  388. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_MAILS").'</td><td>'.yn($conf->global->MAIN_DISABLE_ALL_MAILS).'</td></tr>';
  389. // Separator
  390. print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
  391. // Method
  392. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
  393. $text=$listofmethods[$conf->global->MAIN_MAIL_SENDMODE];
  394. if (empty($text)) $text=$langs->trans("Undefined").img_warning();
  395. print $text;
  396. print '</td></tr>';
  397. // Host server
  398. if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'mail'))
  399. {
  400. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
  401. }
  402. else
  403. {
  404. 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>';
  405. }
  406. // Port
  407. if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'mail'))
  408. {
  409. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
  410. }
  411. else
  412. {
  413. 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>';
  414. }
  415. // SMTPS ID
  416. if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))
  417. {
  418. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>'.$conf->global->MAIN_MAIL_SMTPS_ID.'</td></tr>';
  419. }
  420. // SMTPS PW
  421. if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))
  422. {
  423. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>'.preg_replace('/./','*',$conf->global->MAIN_MAIL_SMTPS_PW).'</td></tr>';
  424. }
  425. // TLS
  426. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
  427. if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))
  428. {
  429. if (function_exists('openssl_open'))
  430. {
  431. print yn($conf->global->MAIN_MAIL_EMAIL_TLS);
  432. }
  433. else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  434. }
  435. else print yn(0).' ('.$langs->trans("NotSupported").')';
  436. print '</td></tr>';
  437. // STARTTLS
  438. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
  439. if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))
  440. {
  441. if (function_exists('openssl_open'))
  442. {
  443. print yn($conf->global->MAIN_MAIL_EMAIL_STARTTLS);
  444. }
  445. else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  446. }
  447. else print yn(0).' ('.$langs->trans("NotSupported").')';
  448. print '</td></tr>';
  449. // Separator
  450. print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
  451. // From
  452. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_FROM",ini_get('sendmail_from')?ini_get('sendmail_from'):$langs->transnoentities("Undefined")).'</td>';
  453. print '<td>'.$conf->global->MAIN_MAIL_EMAIL_FROM;
  454. if (! empty($conf->global->MAIN_MAIL_EMAIL_FROM) && ! isValidEmail($conf->global->MAIN_MAIL_EMAIL_FROM)) print img_warning($langs->trans("ErrorBadEMail"));
  455. print '</td></tr>';
  456. // Default from type
  457. print '<tr '.$bc[$var?1:0].'><td>'.$langs->trans('MAIN_MAIL_DEFAULT_FROMTYPE').'</td>';
  458. print '<td>';
  459. if($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE === 'user'){
  460. print $langs->trans('UserEmail');
  461. } else {
  462. print $langs->trans('CompanyEmail');
  463. }
  464. print '</td></tr>';
  465. // Separator
  466. print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
  467. // Errors To
  468. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ERRORS_TO").'</td>';
  469. print '<td>'.$conf->global->MAIN_MAIL_ERRORS_TO;
  470. if (! empty($conf->global->MAIN_MAIL_ERRORS_TO) && ! isValidEmail($conf->global->MAIN_MAIL_ERRORS_TO)) print img_warning($langs->trans("ErrorBadEMail"));
  471. print '</td></tr>';
  472. // Autocopy to
  473. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
  474. print '<td>';
  475. if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_TO))
  476. {
  477. print $conf->global->MAIN_MAIL_AUTOCOPY_TO;
  478. if (! isValidEmail($conf->global->MAIN_MAIL_AUTOCOPY_TO)) print img_warning($langs->trans("ErrorBadEMail"));
  479. }
  480. else
  481. {
  482. print '&nbsp;';
  483. }
  484. print '</td></tr>';
  485. print '</table>';
  486. dol_fiche_end();
  487. if ($conf->global->MAIN_MAIL_SENDMODE == 'mail' && empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA))
  488. {
  489. print '<br>';
  490. /*
  491. // Warning 1
  492. if ($linuxlike)
  493. {
  494. $sendmailoption=ini_get('mail.force_extra_parameters');
  495. if (empty($sendmailoption) || ! preg_match('/ba/',$sendmailoption))
  496. {
  497. print info_admin($langs->trans("SendmailOptionNotComplete"));
  498. }
  499. }*/
  500. // Warning 2
  501. print info_admin($langs->trans("SendmailOptionMayHurtBuggedMTA"));
  502. }
  503. // Boutons actions
  504. print '<div class="tabsAction">';
  505. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
  506. if ($conf->global->MAIN_MAIL_SENDMODE != 'mail' || ! $linuxlike)
  507. {
  508. if (function_exists('fsockopen') && $port && $server)
  509. {
  510. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
  511. }
  512. }
  513. else
  514. {
  515. print '<a class="butActionRefused" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
  516. }
  517. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&amp;mode=init">'.$langs->trans("DoTestSend").'</a>';
  518. if (! empty($conf->fckeditor->enabled))
  519. {
  520. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testhtml&amp;mode=init">'.$langs->trans("DoTestSendHTML").'</a>';
  521. }
  522. print '</div>';
  523. if ($conf->global->MAIN_MAIL_SENDMODE == 'mail' && ! in_array($action, array('testconnect', 'test', 'testhtml')))
  524. {
  525. $text = $langs->trans("WarningPHPMail");
  526. print info_admin($text);
  527. }
  528. // Run the test to connect
  529. if ($action == 'testconnect')
  530. {
  531. print load_fiche_titre($langs->trans("DoTestServerAvailability"));
  532. include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  533. $mail = new CMailFile('','','','');
  534. $result=$mail->check_server_port($server,$port);
  535. if ($result) print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort",$server,$port).'</div>';
  536. else
  537. {
  538. $errormsg = $langs->trans("ServerNotAvailableOnIPOrPort",$server,$port);
  539. if ($mail->error) {
  540. $errormsg .= ' - '.$mail->error;
  541. }
  542. setEventMessages($errormsg, null, 'errors');
  543. }
  544. print '<br>';
  545. }
  546. // Show email send test form
  547. if ($action == 'test' || $action == 'testhtml')
  548. {
  549. print load_fiche_titre($action == 'testhtml'?$langs->trans("DoTestSendHTML"):$langs->trans("DoTestSend"));
  550. // Cree l'objet formulaire mail
  551. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  552. $formmail = new FormMail($db);
  553. $formmail->fromname = (isset($_POST['fromname'])?$_POST['fromname']:$conf->global->MAIN_MAIL_EMAIL_FROM);
  554. $formmail->frommail = (isset($_POST['frommail'])?$_POST['frommail']:$conf->global->MAIN_MAIL_EMAIL_FROM);
  555. $formmail->trackid=(($action == 'testhtml')?"testhtml":"test");
  556. $formmail->withfromreadonly=0;
  557. $formmail->withsubstit=0;
  558. $formmail->withfrom=1;
  559. $formmail->witherrorsto=1;
  560. $formmail->withto=(! empty($_POST['sendto'])?$_POST['sendto']:($user->email?$user->email:1));
  561. $formmail->withtocc=(! empty($_POST['sendtocc'])?$_POST['sendtocc']:1); // ! empty to keep field if empty
  562. $formmail->withtoccc=(! empty($_POST['sendtoccc'])?$_POST['sendtoccc']:1); // ! empty to keep field if empty
  563. $formmail->withtopic=(isset($_POST['subject'])?$_POST['subject']:$langs->trans("Test"));
  564. $formmail->withtopicreadonly=0;
  565. $formmail->withfile=2;
  566. $formmail->withbody=(isset($_POST['message'])?$_POST['message']:($action == 'testhtml'?$langs->transnoentities("PredefinedMailTestHtml"):$langs->transnoentities("PredefinedMailTest")));
  567. $formmail->withbodyreadonly=0;
  568. $formmail->withcancel=1;
  569. $formmail->withdeliveryreceipt=1;
  570. $formmail->withfckeditor=($action == 'testhtml'?1:0);
  571. $formmail->ckeditortoolbar='dolibarr_mailings';
  572. // Tableau des substitutions
  573. $formmail->substit=$substitutionarrayfortest;
  574. // Tableau des parametres complementaires du post
  575. $formmail->param["action"]="send";
  576. $formmail->param["models"]="body";
  577. $formmail->param["mailid"]=0;
  578. $formmail->param["returnurl"]=$_SERVER["PHP_SELF"];
  579. // Init list of files
  580. if (GETPOST("mode")=='init')
  581. {
  582. $formmail->clear_attached_files();
  583. }
  584. print $formmail->get_form('addfile','removefile');
  585. print '<br>';
  586. }
  587. }
  588. llxFooter();
  589. $db->close();