mails_emailing.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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', 'aZ09');
  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, 2);
  38. }
  39. $substitutionarrayfortest = array(
  40. '__DOL_MAIN_URL_ROOT__'=>DOL_MAIN_URL_ROOT,
  41. '__ID__' => 'RecipientIdRecord',
  42. //'__EMAIL__' => 'RecipientEMail', // Done into actions_sendmails
  43. '__CHECK_READ__' => (!empty($object) && is_object($object) && is_object($object->thirdparty)) ? '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$object->thirdparty->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>' : '',
  44. '__USER_SIGNATURE__' => (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $usersignature : ''), // Done into actions_sendmails
  45. '__LOGIN__' => $user->login,
  46. '__LASTNAME__' => 'RecipientLastname',
  47. '__FIRSTNAME__' => 'RecipientFirstname',
  48. '__ADDRESS__'=> 'RecipientAddress',
  49. '__ZIP__'=> 'RecipientZip',
  50. '__TOWN_'=> 'RecipientTown',
  51. '__COUNTRY__'=> 'RecipientCountry'
  52. );
  53. complete_substitutions_array($substitutionarrayfortest, $langs);
  54. /*
  55. * Actions
  56. */
  57. if ($action == 'update' && !$cancel) {
  58. // Send mode parameters
  59. dolibarr_set_const($db, "MAIN_MAIL_SENDMODE_EMAILING", GETPOST("MAIN_MAIL_SENDMODE_EMAILING"), 'chaine', 0, '', $conf->entity);
  60. dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT_EMAILING", GETPOST("MAIN_MAIL_SMTP_PORT_EMAILING"), 'chaine', 0, '', $conf->entity);
  61. dolibarr_set_const($db, "MAIN_MAIL_SMTP_SERVER_EMAILING", GETPOST("MAIN_MAIL_SMTP_SERVER_EMAILING"), 'chaine', 0, '', $conf->entity);
  62. dolibarr_set_const($db, "MAIN_MAIL_SMTPS_ID_EMAILING", GETPOST("MAIN_MAIL_SMTPS_ID_EMAILING"), 'chaine', 0, '', $conf->entity);
  63. dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW_EMAILING", GETPOST("MAIN_MAIL_SMTPS_PW_EMAILING"), 'chaine', 0, '', $conf->entity);
  64. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS_EMAILING", GETPOST("MAIN_MAIL_EMAIL_TLS_EMAILING"), 'chaine', 0, '', $conf->entity);
  65. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS_EMAILING", GETPOST("MAIN_MAIL_EMAIL_STARTTLS_EMAILING"), 'chaine', 0, '', $conf->entity);
  66. 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);
  67. header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
  68. exit;
  69. }
  70. // Actions to send emails
  71. $id = 0;
  72. $actiontypecode = ''; // Not an event for agenda
  73. $triggersendname = ''; // Disable triggers
  74. $paramname = 'id';
  75. $mode = 'emailfortest';
  76. $trackid = (($action == 'testhtml') ? "testhtml" : "test");
  77. $sendcontext = 'emailing'; // Force to use dedicated context of setup for emailing
  78. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  79. if ($action == 'presend' && GETPOST('trackid', 'alphanohtml') == 'test') {
  80. $action = 'test';
  81. }
  82. if ($action == 'presend' && GETPOST('trackid', 'alphanohtml') == 'testhtml') {
  83. $action = 'testhtml';
  84. }
  85. /*
  86. * View
  87. */
  88. $form = new Form($db);
  89. $linuxlike = 1;
  90. if (preg_match('/^win/i', PHP_OS)) {
  91. $linuxlike = 0;
  92. }
  93. if (preg_match('/^mac/i', PHP_OS)) {
  94. $linuxlike = 0;
  95. }
  96. if (empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING)) {
  97. $conf->global->MAIN_MAIL_SENDMODE_EMAILING = 'default';
  98. }
  99. $port = !empty($conf->global->MAIN_MAIL_SMTP_PORT_EMAILING) ? $conf->global->MAIN_MAIL_SMTP_PORT_EMAILING : ini_get('smtp_port');
  100. if (!$port) {
  101. $port = 25;
  102. }
  103. $server = !empty($conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING) ? $conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING : ini_get('SMTP');
  104. if (!$server) {
  105. $server = '127.0.0.1';
  106. }
  107. $wikihelp = 'EN:Setup_EMails|FR:Paramétrage_EMails|ES:Configuración_EMails';
  108. llxHeader('', $langs->trans("Setup"), $wikihelp);
  109. print load_fiche_titre($langs->trans("EMailsSetup"), '', 'title_setup');
  110. $head = email_admin_prepare_head();
  111. // List of sending methods
  112. $listofmethods = array();
  113. $listofmethods['default'] = $langs->trans('DefaultOutgoingEmailSetup');
  114. $listofmethods['mail'] = 'PHP mail function';
  115. //$listofmethods['simplemail']='Simplemail class';
  116. $listofmethods['smtps'] = 'SMTP/SMTPS socket library';
  117. if (version_compare(phpversion(), '7.0', '>=')) {
  118. $listofmethods['swiftmailer'] = 'Swift Mailer socket library';
  119. }
  120. if ($action == 'edit') {
  121. if ($conf->use_javascript_ajax) {
  122. print "\n".'<script type="text/javascript">';
  123. print 'jQuery(document).ready(function () {
  124. function initfields()
  125. {
  126. if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'default\')
  127. {
  128. jQuery(".hideifdefault").hide();
  129. }
  130. else
  131. {
  132. jQuery(".hideifdefault").show();
  133. }
  134. if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'mail\')
  135. {
  136. jQuery(".drag").hide();
  137. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val(0);
  138. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").prop("disabled", true);
  139. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val(0);
  140. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").prop("disabled", true);
  141. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val(0);
  142. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").prop("disabled", true);
  143. ';
  144. if ($linuxlike) {
  145. print '
  146. jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").hide();
  147. jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").hide();
  148. jQuery("#smtp_server_mess").show();
  149. jQuery("#smtp_port_mess").show();
  150. ';
  151. } else {
  152. print '
  153. jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").prop("disabled", true);
  154. jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").prop("disabled", true);
  155. jQuery("#smtp_server_mess").hide();
  156. jQuery("#smtp_port_mess").hide();
  157. ';
  158. }
  159. print '
  160. }
  161. if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'smtps\')
  162. {
  163. jQuery(".drag").show();
  164. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING.');
  165. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").removeAttr("disabled");
  166. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING.');
  167. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").removeAttr("disabled");
  168. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING.');
  169. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").removeAttr("disabled");
  170. jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").removeAttr("disabled");
  171. jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").removeAttr("disabled");
  172. jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").show();
  173. jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").show();
  174. jQuery("#smtp_server_mess").hide();
  175. jQuery("#smtp_port_mess").hide();
  176. }
  177. if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'swiftmailer\')
  178. {
  179. jQuery(".drag").show();
  180. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING.');
  181. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").removeAttr("disabled");
  182. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING.');
  183. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").removeAttr("disabled");
  184. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING.');
  185. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").removeAttr("disabled");
  186. jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").removeAttr("disabled");
  187. jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").removeAttr("disabled");
  188. jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").show();
  189. jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").show();
  190. jQuery("#smtp_server_mess").hide();
  191. jQuery("#smtp_port_mess").hide();
  192. }
  193. }
  194. initfields();
  195. jQuery("#MAIN_MAIL_SENDMODE_EMAILING").change(function() {
  196. initfields();
  197. });
  198. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").change(function() {
  199. if (jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val() == 1)
  200. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val(0);
  201. else
  202. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val(0);
  203. });
  204. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").change(function() {
  205. if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val() == 1)
  206. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val(0);
  207. else
  208. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val(0);
  209. });
  210. })';
  211. print '</script>'."\n";
  212. }
  213. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  214. print '<input type="hidden" name="token" value="'.newToken().'">';
  215. print '<input type="hidden" name="action" value="update">';
  216. print dol_get_fiche_head($head, 'common_emailing', '', -1);
  217. print '<span class="opacitymedium">'.$langs->trans("EMailsDesc")."</span><br>\n";
  218. print "<br><br>\n";
  219. clearstatcache();
  220. print '<table class="noborder centpercent">';
  221. print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  222. // Method
  223. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
  224. // SuperAdministrator access only
  225. if ((empty($conf->global->MAIN_MODULE_MULTICOMPANY)) || ($user->admin && !$user->entity)) {
  226. print $form->selectarray('MAIN_MAIL_SENDMODE_EMAILING', $listofmethods, $conf->global->MAIN_MAIL_SENDMODE_EMAILING);
  227. } else {
  228. $text = $listofmethods[$conf->global->MAIN_MAIL_SENDMODE_EMAILING];
  229. if (empty($text)) {
  230. $text = $langs->trans("Undefined");
  231. }
  232. $htmltext = $langs->trans("ContactSuperAdminForChange");
  233. print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
  234. print '<input type="hidden" name="MAIN_MAIL_SENDMODE_EMAILING" value="'.$conf->global->MAIN_MAIL_SENDMODE_EMAILING.'">';
  235. }
  236. print '</td></tr>';
  237. // Host server
  238. print '<tr class="oddeven hideifdefault">';
  239. if (!$conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail') {
  240. print '<td>';
  241. print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
  242. print '</td><td>';
  243. print '<span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
  244. print '</td>';
  245. } else {
  246. print '<td>';
  247. $mainserver = (!empty($conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING) ? $conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING : '');
  248. $smtpserver = ini_get('SMTP') ?ini_get('SMTP') : $langs->transnoentities("Undefined");
  249. if ($linuxlike) {
  250. print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
  251. } else {
  252. print $langs->trans("MAIN_MAIL_SMTP_SERVER", $smtpserver);
  253. }
  254. print '</td><td>';
  255. // SuperAdministrator access only
  256. if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity)) {
  257. print '<input class="flat minwidth300" id="MAIN_MAIL_SMTP_SERVER_EMAILING" name="MAIN_MAIL_SMTP_SERVER_EMAILING" size="18" value="'.$mainserver.'">';
  258. print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_EMAILING_sav" name="MAIN_MAIL_SMTP_SERVER_EMAILING_sav" value="'.$mainserver.'">';
  259. print '<span id="smtp_server_mess" class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
  260. print ' <span class="opacitymedium smtp_method">'.$langs->trans("SeeLinkToOnlineDocumentation").'</span>';
  261. } else {
  262. $text = !empty($mainserver) ? $mainserver : $smtpserver;
  263. $htmltext = $langs->trans("ContactSuperAdminForChange");
  264. print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
  265. print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_EMAILING" name="MAIN_MAIL_SMTP_SERVER_EMAILING" value="'.$mainserver.'">';
  266. }
  267. print '</td>';
  268. }
  269. print '</tr>';
  270. // Port
  271. print '<tr class="oddeven hideifdefault"><td>';
  272. if (!$conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail') {
  273. print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
  274. print '</td><td>';
  275. print '<span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
  276. } else {
  277. $mainport = (!empty($conf->global->MAIN_MAIL_SMTP_PORT_EMAILING) ? $conf->global->MAIN_MAIL_SMTP_PORT_EMAILING : '');
  278. $smtpport = ini_get('smtp_port') ?ini_get('smtp_port') : $langs->transnoentities("Undefined");
  279. if ($linuxlike) {
  280. print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
  281. } else {
  282. print $langs->trans("MAIN_MAIL_SMTP_PORT", $smtpport);
  283. }
  284. print '</td><td>';
  285. // SuperAdministrator access only
  286. if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity)) {
  287. print '<input class="flat" id="MAIN_MAIL_SMTP_PORT_EMAILING" name="MAIN_MAIL_SMTP_PORT_EMAILING" size="3" value="'.$mainport.'">';
  288. print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_EMAILING_sav" name="MAIN_MAIL_SMTP_PORT_EMAILING_sav" value="'.$mainport.'">';
  289. print '<span id="smtp_port_mess" class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
  290. } else {
  291. $text = (!empty($mainport) ? $mainport : $smtpport);
  292. $htmltext = $langs->trans("ContactSuperAdminForChange");
  293. print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
  294. print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_EMAILING" name="MAIN_MAIL_SMTP_PORT_EMAILING" value="'.$mainport.'">';
  295. }
  296. }
  297. print '</td></tr>';
  298. // ID
  299. if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))) {
  300. $mainstmpid = (!empty($conf->global->MAIN_MAIL_SMTPS_ID_EMAILING) ? $conf->global->MAIN_MAIL_SMTPS_ID_EMAILING : '');
  301. print '<tr class="drag drop oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>';
  302. // SuperAdministrator access only
  303. if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity)) {
  304. print '<input class="flat" name="MAIN_MAIL_SMTPS_ID_EMAILING" size="32" value="'.$mainstmpid.'">';
  305. } else {
  306. $htmltext = $langs->trans("ContactSuperAdminForChange");
  307. print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_ID_EMAILING, $htmltext, 1, 'superadmin');
  308. print '<input type="hidden" name="MAIN_MAIL_SMTPS_ID_EMAILING" value="'.$mainstmpid.'">';
  309. }
  310. print '</td></tr>';
  311. }
  312. // PW
  313. if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))) {
  314. $mainsmtppw = (!empty($conf->global->MAIN_MAIL_SMTPS_PW_EMAILING) ? $conf->global->MAIN_MAIL_SMTPS_PW_EMAILING : '');
  315. print '<tr class="drag drop oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>';
  316. // SuperAdministrator access only
  317. if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity)) {
  318. print '<input class="flat" type="password" name="MAIN_MAIL_SMTPS_PW_EMAILING" size="32" value="'.$mainsmtppw.'">';
  319. } else {
  320. $htmltext = $langs->trans("ContactSuperAdminForChange");
  321. print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_PW_EMAILING, $htmltext, 1, 'superadmin');
  322. print '<input type="hidden" name="MAIN_MAIL_SMTPS_PW_EMAILING" value="'.$mainsmtppw.'">';
  323. }
  324. print '</td></tr>';
  325. }
  326. // TLS
  327. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
  328. if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))) {
  329. if (function_exists('openssl_open')) {
  330. 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);
  331. } else {
  332. print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  333. }
  334. } else {
  335. print yn(0).' ('.$langs->trans("NotSupported").')';
  336. }
  337. print '</td></tr>';
  338. // STARTTLS
  339. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
  340. if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))) {
  341. if (function_exists('openssl_open')) {
  342. 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);
  343. } else {
  344. print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  345. }
  346. } else {
  347. print yn(0).' ('.$langs->trans("NotSupported").')';
  348. }
  349. print '</td></tr>';
  350. // SMTP_ALLOW_SELF_SIGNED_EMAILING
  351. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").'</td><td>';
  352. if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))) {
  353. if (function_exists('openssl_open')) {
  354. 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);
  355. } else {
  356. print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  357. }
  358. } else {
  359. print yn(0).' ('.$langs->trans("NotSupported").')';
  360. }
  361. print '</td></tr>';
  362. print '</table>';
  363. print dol_get_fiche_end();
  364. print $form->buttonsSaveCancel();
  365. print '</form>';
  366. } else {
  367. print dol_get_fiche_head($head, 'common_emailing', '', -1);
  368. print '<span class="opacitymedium">'.$langs->trans("EMailsDesc")."</span><br>\n";
  369. print "<br><br>\n";
  370. print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  371. print '<table class="noborder centpercent">';
  372. print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  373. // Method
  374. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
  375. $text = $listofmethods[getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING')];
  376. if (empty($text)) {
  377. $text = $langs->trans("Undefined").img_warning();
  378. }
  379. if (getDolGlobalString('MAIN_MAIL_SENDMODE_EMAILING') == 'default') {
  380. print '<span class="opacitymedium">'.$text.'</span>';
  381. } else {
  382. print $text;
  383. }
  384. print '</td></tr>';
  385. if (!empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default') {
  386. // Host server
  387. if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail')) {
  388. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
  389. } else {
  390. 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>';
  391. }
  392. // Port
  393. if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail')) {
  394. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
  395. } else {
  396. 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>';
  397. }
  398. // SMTPS ID
  399. if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))) {
  400. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>'.getDolGlobalString('MAIN_MAIL_SMTPS_ID_EMAILING').'</td></tr>';
  401. }
  402. // SMTPS PW
  403. if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))) {
  404. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>'.preg_replace('/./', '*', getDolGlobalString('MAIN_MAIL_SMTPS_PW_EMAILING')).'</td></tr>';
  405. }
  406. // TLS
  407. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
  408. if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))) {
  409. if (function_exists('openssl_open')) {
  410. print yn($conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING);
  411. } else {
  412. print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  413. }
  414. } else {
  415. print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
  416. }
  417. print '</td></tr>';
  418. // STARTTLS
  419. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
  420. if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))) {
  421. if (function_exists('openssl_open')) {
  422. print yn($conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING);
  423. } else {
  424. print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  425. }
  426. } else {
  427. print yn(0).' ('.$langs->trans("NotSupported").')';
  428. }
  429. print '</td></tr>';
  430. // SMTP_ALLOW_SELF_SIGNED_EMAILING
  431. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").'</td><td>';
  432. if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))) {
  433. if (function_exists('openssl_open')) {
  434. print yn(getDolGlobalInt('MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING'));
  435. } else {
  436. print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  437. }
  438. } else {
  439. print yn(0).' ('.$langs->trans("NotSupported").')';
  440. }
  441. print '</td></tr>';
  442. }
  443. print '</table>';
  444. print '</div>';
  445. print dol_get_fiche_end();
  446. if ($conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail' && empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)) {
  447. print '<br>';
  448. /*
  449. // Warning 1
  450. if ($linuxlike) {
  451. $sendmailoption=ini_get('mail.force_extra_parameters');
  452. if (empty($sendmailoption) || ! preg_match('/ba/',$sendmailoption)) {
  453. print info_admin($langs->trans("SendmailOptionNotComplete"));
  454. }
  455. }*/
  456. // Warning 2
  457. print info_admin($langs->trans("SendmailOptionMayHurtBuggedMTA"));
  458. }
  459. // Buttons for actions
  460. print '<div class="tabsAction">';
  461. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
  462. if (!empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default') {
  463. if ($conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'mail' || !$linuxlike) {
  464. if (function_exists('fsockopen') && $port && $server) {
  465. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
  466. }
  467. } else {
  468. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
  469. }
  470. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&amp;mode=init">'.$langs->trans("DoTestSend").'</a>';
  471. if (!empty($conf->fckeditor->enabled)) {
  472. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testhtml&amp;mode=init">'.$langs->trans("DoTestSendHTML").'</a>';
  473. }
  474. }
  475. print '</div>';
  476. if ($conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail' && !in_array($action, array('testconnect', 'test', 'testhtml'))) {
  477. $text = $langs->trans("WarningPHPMail");
  478. print info_admin($text);
  479. }
  480. // Run the test to connect
  481. if ($action == 'testconnect') {
  482. print '<div id="formmailaftertstconnect" name="formmailaftertstconnect"></div>';
  483. print load_fiche_titre($langs->trans("DoTestServerAvailability"));
  484. include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  485. $mail = new CMailFile('', '', '', '', array(), array(), array(), '', '', 0, '', '', '', '', $trackid, $sendcontext);
  486. $result = $mail->check_server_port($server, $port);
  487. if ($result) {
  488. print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort", $server, $port).'</div>';
  489. } else {
  490. $errormsg = $langs->trans("ServerNotAvailableOnIPOrPort", $server, $port);
  491. if ($mail->error) {
  492. $errormsg .= ' - '.$mail->error;
  493. }
  494. setEventMessages($errormsg, null, 'errors');
  495. }
  496. print '<br>';
  497. }
  498. // Show email send test form
  499. if ($action == 'test' || $action == 'testhtml') {
  500. print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
  501. print load_fiche_titre($action == 'testhtml' ? $langs->trans("DoTestSendHTML") : $langs->trans("DoTestSend"));
  502. print dol_get_fiche_head('');
  503. // Cree l'objet formulaire mail
  504. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  505. $formmail = new FormMail($db);
  506. $formmail->trackid = (($action == 'testhtml') ? "testhtml" : "test");
  507. $formmail->fromname = (GETPOSTISSET('fromname') ? GETPOST('fromname', 'restricthtml') : $conf->global->MAIN_MAIL_EMAIL_FROM);
  508. $formmail->frommail = (GETPOSTISSET('frommail') ? GETPOST('frommail', 'restricthtml') : $conf->global->MAIN_MAIL_EMAIL_FROM);
  509. $formmail->fromid = $user->id;
  510. $formmail->fromalsorobot = 1;
  511. $formmail->withfromreadonly = 0;
  512. $formmail->withsubstit = 0;
  513. $formmail->withfrom = 1;
  514. $formmail->witherrorsto = 1;
  515. $formmail->withto = (GETPOSTISSET('sendto') ? GETPOST('sendto', 'restricthtml') : ($user->email ? $user->email : 1));
  516. $formmail->withtocc = (GETPOSTISSET(['sendtocc']) ? GETPOST('sendtocc', 'restricthtml') : 1); // ! empty to keep field if empty
  517. $formmail->withtoccc = (GETPOSTISSET(['sendtoccc']) ? GETPOST('sendtoccc', 'restricthtml') : 1); // ! empty to keep field if empty
  518. $formmail->withtopic = (GETPOSTISSET('subject') ? GETPOST('subject') : $langs->trans("Test"));
  519. $formmail->withtopicreadonly = 0;
  520. $formmail->withfile = 2;
  521. $formmail->withbody = (GETPOSTISSET('message') ? GETPOST('message', 'restricthtml') : ($action == 'testhtml' ? $langs->transnoentities("PredefinedMailTestHtml") : $langs->transnoentities("PredefinedMailTest")));
  522. $formmail->withbodyreadonly = 0;
  523. $formmail->withcancel = 1;
  524. $formmail->withdeliveryreceipt = 1;
  525. $formmail->withfckeditor = ($action == 'testhtml' ? 1 : 0);
  526. $formmail->ckeditortoolbar = 'dolibarr_mailings';
  527. // Tableau des substitutions
  528. $formmail->substit = $substitutionarrayfortest;
  529. // Tableau des parametres complementaires du post
  530. $formmail->param["action"] = "send";
  531. $formmail->param["models"] = "body";
  532. $formmail->param["mailid"] = 0;
  533. $formmail->param["returnurl"] = $_SERVER["PHP_SELF"];
  534. // Init list of files
  535. if (GETPOST("mode", "aZ09") == 'init') {
  536. $formmail->clear_attached_files();
  537. }
  538. print $formmail->get_form('addfile', 'removefile');
  539. print dol_get_fiche_end();
  540. }
  541. }
  542. // End of page
  543. llxFooter();
  544. $db->close();