mails_emailing.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2016 Jonathan TISSEAU <jonathan.tisseau@86dev.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  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. // Load translation files required by the page
  28. $langs->loadLangs(array('companies', 'products', 'admin', 'mails', 'other', 'errors'));
  29. $action = GETPOST('action', 'aZ09');
  30. $cancel = GETPOST('cancel', 'alpha');
  31. if (!$user->admin) {
  32. accessforbidden();
  33. }
  34. $usersignature = $user->signature;
  35. // For action = test or send, we ensure that content is not html, even for signature, because this we want a test with NO html.
  36. if ($action == 'test' || $action == 'send') {
  37. $usersignature = dol_string_nohtmltag($usersignature);
  38. }
  39. $substitutionarrayfortest = array(
  40. '__LOGIN__' => $user->login,
  41. '__ID__' => 'TESTIdRecord',
  42. '__EMAIL__' => 'TESTEMail',
  43. '__LASTNAME__' => 'TESTLastname',
  44. '__FIRSTNAME__' => 'TESTFirstname',
  45. '__USER_SIGNATURE__' => (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $usersignature : ''),
  46. //'__PERSONALIZED__' => 'TESTPersonalized' // Hiden because not used yet
  47. );
  48. complete_substitutions_array($substitutionarrayfortest, $langs);
  49. /*
  50. * Actions
  51. */
  52. if ($action == 'update' && !$cancel) {
  53. // Send mode parameters
  54. dolibarr_set_const($db, "MAIN_MAIL_SENDMODE_EMAILING", GETPOST("MAIN_MAIL_SENDMODE_EMAILING"), 'chaine', 0, '', $conf->entity);
  55. dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT_EMAILING", GETPOST("MAIN_MAIL_SMTP_PORT_EMAILING"), 'chaine', 0, '', $conf->entity);
  56. dolibarr_set_const($db, "MAIN_MAIL_SMTP_SERVER_EMAILING", GETPOST("MAIN_MAIL_SMTP_SERVER_EMAILING"), 'chaine', 0, '', $conf->entity);
  57. dolibarr_set_const($db, "MAIN_MAIL_SMTPS_ID_EMAILING", GETPOST("MAIN_MAIL_SMTPS_ID_EMAILING"), 'chaine', 0, '', $conf->entity);
  58. dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW_EMAILING", GETPOST("MAIN_MAIL_SMTPS_PW_EMAILING"), 'chaine', 0, '', $conf->entity);
  59. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS_EMAILING", GETPOST("MAIN_MAIL_EMAIL_TLS_EMAILING"), 'chaine', 0, '', $conf->entity);
  60. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS_EMAILING", GETPOST("MAIN_MAIL_EMAIL_STARTTLS_EMAILING"), 'chaine', 0, '', $conf->entity);
  61. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING", GETPOST("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING"), 'chaine', 0, '', $conf->entity);
  62. header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
  63. exit;
  64. }
  65. // Actions to send emails
  66. $id = 0;
  67. $actiontypecode = ''; // Not an event for agenda
  68. $triggersendname = ''; // Disable triggers
  69. $paramname = 'id';
  70. $mode = 'emailfortest';
  71. $trackid = (($action == 'testhtml') ? "testhtml" : "test");
  72. $sendcontext = 'emailing'; // Force to use dedicated context of setup for emailing
  73. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  74. if ($action == 'presend' && GETPOST('trackid') == 'test') {
  75. $action = 'test';
  76. }
  77. if ($action == 'presend' && GETPOST('trackid') == 'testhtml') {
  78. $action = 'testhtml';
  79. }
  80. /*
  81. * View
  82. */
  83. $form = new Form($db);
  84. $linuxlike = 1;
  85. if (preg_match('/^win/i', PHP_OS)) {
  86. $linuxlike = 0;
  87. }
  88. if (preg_match('/^mac/i', PHP_OS)) {
  89. $linuxlike = 0;
  90. }
  91. if (empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING)) {
  92. $conf->global->MAIN_MAIL_SENDMODE_EMAILING = 'default';
  93. }
  94. $port = !empty($conf->global->MAIN_MAIL_SMTP_PORT_EMAILING) ? $conf->global->MAIN_MAIL_SMTP_PORT_EMAILING : ini_get('smtp_port');
  95. if (!$port) {
  96. $port = 25;
  97. }
  98. $server = !empty($conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING) ? $conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING : ini_get('SMTP');
  99. if (!$server) {
  100. $server = '127.0.0.1';
  101. }
  102. $wikihelp = 'EN:Setup_EMails|FR:Paramétrage_EMails|ES:Configuración_EMails';
  103. llxHeader('', $langs->trans("Setup"), $wikihelp);
  104. print load_fiche_titre($langs->trans("EMailsSetup"), '', 'title_setup');
  105. $head = email_admin_prepare_head();
  106. // List of sending methods
  107. $listofmethods = array();
  108. $listofmethods['default'] = $langs->trans('DefaultOutgoingEmailSetup');
  109. $listofmethods['mail'] = 'PHP mail function';
  110. //$listofmethods['simplemail']='Simplemail class';
  111. $listofmethods['smtps'] = 'SMTP/SMTPS socket library';
  112. if (version_compare(phpversion(), '7.0', '>=')) {
  113. $listofmethods['swiftmailer'] = 'Swift Mailer socket library';
  114. }
  115. if ($action == 'edit') {
  116. if ($conf->use_javascript_ajax) {
  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_EMAILING").val()==\'default\')
  122. {
  123. jQuery(".hideifdefault").hide();
  124. }
  125. else
  126. {
  127. jQuery(".hideifdefault").show();
  128. }
  129. if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'mail\')
  130. {
  131. jQuery(".drag").hide();
  132. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val(0);
  133. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").prop("disabled", true);
  134. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val(0);
  135. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").prop("disabled", true);
  136. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val(0);
  137. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").prop("disabled", true);
  138. ';
  139. if ($linuxlike) {
  140. print '
  141. jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").hide();
  142. jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").hide();
  143. jQuery("#smtp_server_mess").show();
  144. jQuery("#smtp_port_mess").show();
  145. ';
  146. } else {
  147. print '
  148. jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").prop("disabled", true);
  149. jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").prop("disabled", true);
  150. jQuery("#smtp_server_mess").hide();
  151. jQuery("#smtp_port_mess").hide();
  152. ';
  153. }
  154. print '
  155. }
  156. if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'smtps\')
  157. {
  158. jQuery(".drag").show();
  159. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING.');
  160. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").removeAttr("disabled");
  161. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING.');
  162. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").removeAttr("disabled");
  163. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING.');
  164. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").removeAttr("disabled");
  165. jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").removeAttr("disabled");
  166. jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").removeAttr("disabled");
  167. jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").show();
  168. jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").show();
  169. jQuery("#smtp_server_mess").hide();
  170. jQuery("#smtp_port_mess").hide();
  171. }
  172. if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'swiftmailer\')
  173. {
  174. jQuery(".drag").show();
  175. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING.');
  176. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").removeAttr("disabled");
  177. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING.');
  178. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").removeAttr("disabled");
  179. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING.');
  180. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").removeAttr("disabled");
  181. jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").removeAttr("disabled");
  182. jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").removeAttr("disabled");
  183. jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").show();
  184. jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").show();
  185. jQuery("#smtp_server_mess").hide();
  186. jQuery("#smtp_port_mess").hide();
  187. }
  188. }
  189. initfields();
  190. jQuery("#MAIN_MAIL_SENDMODE_EMAILING").change(function() {
  191. initfields();
  192. });
  193. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").change(function() {
  194. if (jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val() == 1)
  195. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val(0);
  196. else
  197. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val(0);
  198. });
  199. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").change(function() {
  200. if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val() == 1)
  201. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val(0);
  202. else
  203. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val(0);
  204. });
  205. })';
  206. print '</script>'."\n";
  207. }
  208. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  209. print '<input type="hidden" name="token" value="'.newToken().'">';
  210. print '<input type="hidden" name="action" value="update">';
  211. print dol_get_fiche_head($head, 'common_emailing', '', -1);
  212. print '<span class="opacitymedium">'.$langs->trans("EMailsDesc")."</span><br>\n";
  213. print "<br>\n";
  214. clearstatcache();
  215. print '<table class="noborder centpercent">';
  216. print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  217. // Method
  218. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
  219. // SuperAdministrator access only
  220. if ((empty($conf->global->MAIN_MODULE_MULTICOMPANY)) || ($user->admin && !$user->entity)) {
  221. print $form->selectarray('MAIN_MAIL_SENDMODE_EMAILING', $listofmethods, $conf->global->MAIN_MAIL_SENDMODE_EMAILING);
  222. } else {
  223. $text = $listofmethods[$conf->global->MAIN_MAIL_SENDMODE_EMAILING];
  224. if (empty($text)) {
  225. $text = $langs->trans("Undefined");
  226. }
  227. $htmltext = $langs->trans("ContactSuperAdminForChange");
  228. print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
  229. print '<input type="hidden" name="MAIN_MAIL_SENDMODE_EMAILING" value="'.$conf->global->MAIN_MAIL_SENDMODE_EMAILING.'">';
  230. }
  231. print '</td></tr>';
  232. // Host server
  233. print '<tr class="oddeven hideifdefault"><td>';
  234. if (!$conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail') {
  235. print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
  236. print '</td><td>';
  237. print $langs->trans("SeeLocalSendMailSetup");
  238. } else {
  239. $mainserver = (!empty($conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING) ? $conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING : '');
  240. $smtpserver = ini_get('SMTP') ?ini_get('SMTP') : $langs->transnoentities("Undefined");
  241. if ($linuxlike) {
  242. print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
  243. } else {
  244. print $langs->trans("MAIN_MAIL_SMTP_SERVER", $smtpserver);
  245. }
  246. print '</td><td>';
  247. // SuperAdministrator access only
  248. if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity)) {
  249. print '<input class="flat" id="MAIN_MAIL_SMTP_SERVER_EMAILING" name="MAIN_MAIL_SMTP_SERVER_EMAILING" size="18" value="'.$mainserver.'">';
  250. print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_EMAILING_sav" name="MAIN_MAIL_SMTP_SERVER_EMAILING_sav" value="'.$mainserver.'">';
  251. print '<span id="smtp_server_mess">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
  252. } else {
  253. $text = !empty($mainserver) ? $mainserver : $smtpserver;
  254. $htmltext = $langs->trans("ContactSuperAdminForChange");
  255. print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
  256. print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_EMAILING" name="MAIN_MAIL_SMTP_SERVER_EMAILING" value="'.$mainserver.'">';
  257. }
  258. }
  259. print '</td></tr>';
  260. // Port
  261. print '<tr class="oddeven hideifdefault"><td>';
  262. if (!$conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail') {
  263. print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
  264. print '</td><td>';
  265. print $langs->trans("SeeLocalSendMailSetup");
  266. } else {
  267. $mainport = (!empty($conf->global->MAIN_MAIL_SMTP_PORT_EMAILING) ? $conf->global->MAIN_MAIL_SMTP_PORT_EMAILING : '');
  268. $smtpport = ini_get('smtp_port') ?ini_get('smtp_port') : $langs->transnoentities("Undefined");
  269. if ($linuxlike) {
  270. print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
  271. } else {
  272. print $langs->trans("MAIN_MAIL_SMTP_PORT", $smtpport);
  273. }
  274. print '</td><td>';
  275. // SuperAdministrator access only
  276. if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity)) {
  277. print '<input class="flat" id="MAIN_MAIL_SMTP_PORT_EMAILING" name="MAIN_MAIL_SMTP_PORT_EMAILING" size="3" value="'.$mainport.'">';
  278. print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_EMAILING_sav" name="MAIN_MAIL_SMTP_PORT_EMAILING_sav" value="'.$mainport.'">';
  279. print '<span id="smtp_port_mess">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
  280. } else {
  281. $text = (!empty($mainport) ? $mainport : $smtpport);
  282. $htmltext = $langs->trans("ContactSuperAdminForChange");
  283. print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
  284. print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_EMAILING" name="MAIN_MAIL_SMTP_PORT_EMAILING" value="'.$mainport.'">';
  285. }
  286. }
  287. print '</td></tr>';
  288. // ID
  289. if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))) {
  290. $mainstmpid = (!empty($conf->global->MAIN_MAIL_SMTPS_ID_EMAILING) ? $conf->global->MAIN_MAIL_SMTPS_ID_EMAILING : '');
  291. print '<tr class="drag drop oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>';
  292. // SuperAdministrator access only
  293. if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity)) {
  294. print '<input class="flat" name="MAIN_MAIL_SMTPS_ID_EMAILING" size="32" value="'.$mainstmpid.'">';
  295. } else {
  296. $htmltext = $langs->trans("ContactSuperAdminForChange");
  297. print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_ID_EMAILING, $htmltext, 1, 'superadmin');
  298. print '<input type="hidden" name="MAIN_MAIL_SMTPS_ID_EMAILING" value="'.$mainstmpid.'">';
  299. }
  300. print '</td></tr>';
  301. }
  302. // PW
  303. if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))) {
  304. $mainsmtppw = (!empty($conf->global->MAIN_MAIL_SMTPS_PW_EMAILING) ? $conf->global->MAIN_MAIL_SMTPS_PW_EMAILING : '');
  305. print '<tr class="drag drop oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>';
  306. // SuperAdministrator access only
  307. if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity)) {
  308. print '<input class="flat" type="password" name="MAIN_MAIL_SMTPS_PW_EMAILING" size="32" value="'.$mainsmtppw.'">';
  309. } else {
  310. $htmltext = $langs->trans("ContactSuperAdminForChange");
  311. print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_PW_EMAILING, $htmltext, 1, 'superadmin');
  312. print '<input type="hidden" name="MAIN_MAIL_SMTPS_PW_EMAILING" value="'.$mainsmtppw.'">';
  313. }
  314. print '</td></tr>';
  315. }
  316. // TLS
  317. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
  318. if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))) {
  319. if (function_exists('openssl_open')) {
  320. print $form->selectyesno('MAIN_MAIL_EMAIL_TLS_EMAILING', (!empty($conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING) ? $conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING : 0), 1);
  321. } else {
  322. print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  323. }
  324. } else {
  325. print yn(0).' ('.$langs->trans("NotSupported").')';
  326. }
  327. print '</td></tr>';
  328. // STARTTLS
  329. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
  330. if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))) {
  331. if (function_exists('openssl_open')) {
  332. print $form->selectyesno('MAIN_MAIL_EMAIL_STARTTLS_EMAILING', (!empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING) ? $conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING : 0), 1);
  333. } else {
  334. print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  335. }
  336. } else {
  337. print yn(0).' ('.$langs->trans("NotSupported").')';
  338. }
  339. print '</td></tr>';
  340. // SMTP_ALLOW_SELF_SIGNED_EMAILING
  341. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").'</td><td>';
  342. if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))) {
  343. if (function_exists('openssl_open')) {
  344. print $form->selectyesno('MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING', (!empty($conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING) ? $conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING : 0), 1);
  345. } else {
  346. print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  347. }
  348. } else {
  349. print yn(0).' ('.$langs->trans("NotSupported").')';
  350. }
  351. print '</td></tr>';
  352. print '</table>';
  353. print dol_get_fiche_end();
  354. print '<br><div class="center">';
  355. print '<input class="button button-save" type="submit" name="save" value="'.$langs->trans("Save").'">';
  356. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  357. print '<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  358. print '</div>';
  359. print '</form>';
  360. } else {
  361. print dol_get_fiche_head($head, 'common_emailing', '', -1);
  362. print '<span class="opacitymedium">'.$langs->trans("EMailsDesc")."</span><br>\n";
  363. print "<br>\n";
  364. print '<table class="noborder centpercent">';
  365. print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  366. // Method
  367. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
  368. $text = $listofmethods[$conf->global->MAIN_MAIL_SENDMODE_EMAILING];
  369. if (empty($text)) {
  370. $text = $langs->trans("Undefined").img_warning();
  371. }
  372. print $text;
  373. print '</td></tr>';
  374. if (!empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default') {
  375. // Host server
  376. if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail')) {
  377. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
  378. } else {
  379. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER", ini_get('SMTP') ?ini_get('SMTP') : $langs->transnoentities("Undefined")).'</td><td>'.(!empty($conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING) ? $conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING : '').'</td></tr>';
  380. }
  381. // Port
  382. if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail')) {
  383. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
  384. } else {
  385. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT", ini_get('smtp_port') ?ini_get('smtp_port') : $langs->transnoentities("Undefined")).'</td><td>'.(!empty($conf->global->MAIN_MAIL_SMTP_PORT_EMAILING) ? $conf->global->MAIN_MAIL_SMTP_PORT_EMAILING : '').'</td></tr>';
  386. }
  387. // SMTPS ID
  388. if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))) {
  389. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>'.getDolGlobalString('MAIN_MAIL_SMTPS_ID_EMAILING').'</td></tr>';
  390. }
  391. // SMTPS PW
  392. if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))) {
  393. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>'.preg_replace('/./', '*', getDolGlobalString('MAIN_MAIL_SMTPS_PW_EMAILING')).'</td></tr>';
  394. }
  395. // TLS
  396. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
  397. if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))) {
  398. if (function_exists('openssl_open')) {
  399. print yn($conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING);
  400. } else {
  401. print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  402. }
  403. } else {
  404. print yn(0).' ('.$langs->trans("NotSupported").')';
  405. }
  406. print '</td></tr>';
  407. // STARTTLS
  408. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
  409. if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))) {
  410. if (function_exists('openssl_open')) {
  411. print yn($conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING);
  412. } else {
  413. print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  414. }
  415. } else {
  416. print yn(0).' ('.$langs->trans("NotSupported").')';
  417. }
  418. print '</td></tr>';
  419. // SMTP_ALLOW_SELF_SIGNED_EMAILING
  420. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").'</td><td>';
  421. if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))) {
  422. if (function_exists('openssl_open')) {
  423. print yn(getDolGlobalInt('MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING'));
  424. } else {
  425. print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  426. }
  427. } else {
  428. print yn(0).' ('.$langs->trans("NotSupported").')';
  429. }
  430. print '</td></tr>';
  431. }
  432. print '</table>';
  433. print dol_get_fiche_end();
  434. if ($conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail' && empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)) {
  435. print '<br>';
  436. /*
  437. // Warning 1
  438. if ($linuxlike) {
  439. $sendmailoption=ini_get('mail.force_extra_parameters');
  440. if (empty($sendmailoption) || ! preg_match('/ba/',$sendmailoption)) {
  441. print info_admin($langs->trans("SendmailOptionNotComplete"));
  442. }
  443. }*/
  444. // Warning 2
  445. print info_admin($langs->trans("SendmailOptionMayHurtBuggedMTA"));
  446. }
  447. // Buttons for actions
  448. print '<div class="tabsAction">';
  449. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
  450. if (!empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default') {
  451. if ($conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'mail' || !$linuxlike) {
  452. if (function_exists('fsockopen') && $port && $server) {
  453. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
  454. }
  455. } else {
  456. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
  457. }
  458. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&amp;mode=init">'.$langs->trans("DoTestSend").'</a>';
  459. if (!empty($conf->fckeditor->enabled)) {
  460. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testhtml&amp;mode=init">'.$langs->trans("DoTestSendHTML").'</a>';
  461. }
  462. }
  463. print '</div>';
  464. if ($conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail' && !in_array($action, array('testconnect', 'test', 'testhtml'))) {
  465. $text = $langs->trans("WarningPHPMail");
  466. print info_admin($text);
  467. }
  468. // Run the test to connect
  469. if ($action == 'testconnect') {
  470. print load_fiche_titre($langs->trans("DoTestServerAvailability"));
  471. include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  472. $mail = new CMailFile('', '', '', '', array(), array(), array(), '', '', 0, '', '', '', '', $trackid, $sendcontext);
  473. $result = $mail->check_server_port($server, $port);
  474. if ($result) {
  475. print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort", $server, $port).'</div>';
  476. } else {
  477. $errormsg = $langs->trans("ServerNotAvailableOnIPOrPort", $server, $port);
  478. if ($mail->error) {
  479. $errormsg .= ' - '.$mail->error;
  480. }
  481. setEventMessages($errormsg, null, 'errors');
  482. }
  483. print '<br>';
  484. }
  485. // Show email send test form
  486. if ($action == 'test' || $action == 'testhtml') {
  487. print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
  488. print load_fiche_titre($action == 'testhtml' ? $langs->trans("DoTestSendHTML") : $langs->trans("DoTestSend"));
  489. print dol_get_fiche_head('');
  490. // Cree l'objet formulaire mail
  491. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  492. $formmail = new FormMail($db);
  493. $formmail->fromname = (GETPOSTISSET('fromname') ? GETPOST('fromname', 'restricthtml') : $conf->global->MAIN_MAIL_EMAIL_FROM);
  494. $formmail->frommail = (GETPOSTISSET('frommail') ? GETPOST('frommail', 'restricthtml') : $conf->global->MAIN_MAIL_EMAIL_FROM);
  495. $formmail->trackid = (($action == 'testhtml') ? "testhtml" : "test");
  496. $formmail->withfromreadonly = 0;
  497. $formmail->withsubstit = 0;
  498. $formmail->withfrom = 1;
  499. $formmail->witherrorsto = 1;
  500. $formmail->withto = (!GETPOST('sendto') ? GETPOST('sendto', 'restricthtml') : ($user->email ? $user->email : 1));
  501. $formmail->withtocc = (!GETPOST(['sendtocc']) ? GETPOST('sendtocc', 'restricthtml') : 1); // ! empty to keep field if empty
  502. $formmail->withtoccc = (!GETPOST(['sendtoccc']) ? GETPOST('sendtoccc', 'restricthtml') : 1); // ! empty to keep field if empty
  503. $formmail->withtopic = (GETPOSTISSET('subject') ? GETPOST('subject') : $langs->trans("Test"));
  504. $formmail->withtopicreadonly = 0;
  505. $formmail->withfile = 2;
  506. $formmail->withbody = (GETPOSTISSET('message') ? GETPOST('message', 'restricthtml') : ($action == 'testhtml' ? $langs->transnoentities("PredefinedMailTestHtml") : $langs->transnoentities("PredefinedMailTest")));
  507. $formmail->withbodyreadonly = 0;
  508. $formmail->withcancel = 1;
  509. $formmail->withdeliveryreceipt = 1;
  510. $formmail->withfckeditor = ($action == 'testhtml' ? 1 : 0);
  511. $formmail->ckeditortoolbar = 'dolibarr_mailings';
  512. // Tableau des substitutions
  513. $formmail->substit = $substitutionarrayfortest;
  514. // Tableau des parametres complementaires du post
  515. $formmail->param["action"] = "send";
  516. $formmail->param["models"] = "body";
  517. $formmail->param["mailid"] = 0;
  518. $formmail->param["returnurl"] = $_SERVER["PHP_SELF"];
  519. // Init list of files
  520. if (GETPOST("mode") == 'init') {
  521. $formmail->clear_attached_files();
  522. }
  523. print $formmail->get_form('addfile', 'removefile');
  524. print dol_get_fiche_end();
  525. }
  526. }
  527. // End of page
  528. llxFooter();
  529. $db->close();