mails.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964
  1. <?php
  2. /* Copyright (C) 2007-2020 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. '__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"/>' : '',
  42. '__USER_LOGIN__' => $user->login,
  43. '__USER_EMAIL__' => $user->email,
  44. '__USER_SIGNATURE__' => (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $usersignature : ''), // Done into actions_sendmails
  45. '__ID__' => 'RecipientIdRecord',
  46. //'__EMAIL__' => 'RecipientEMail', // Done into actions_sendmails
  47. '__LASTNAME__' => 'RecipientLastname',
  48. '__FIRSTNAME__' => 'RecipientFirstname',
  49. '__ADDRESS__'=> 'RecipientAddress',
  50. '__ZIP__'=> 'RecipientZip',
  51. '__TOWN_'=> 'RecipientTown',
  52. '__COUNTRY__'=> 'RecipientCountry'
  53. );
  54. complete_substitutions_array($substitutionarrayfortest, $langs);
  55. /*
  56. * Actions
  57. */
  58. if ($action == 'update' && !$cancel) {
  59. if (!$error && !GETPOST("MAIN_MAIL_EMAIL_FROM", 'alphanohtml')) {
  60. $error++;
  61. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("MAIN_MAIL_EMAIL_FROM")), null, 'errors');
  62. $action = 'edit';
  63. }
  64. if (!$error && !isValidEmail(GETPOST("MAIN_MAIL_EMAIL_FROM", 'alphanohtml'))) {
  65. $error++;
  66. setEventMessages($langs->trans("ErrorBadEMail", GETPOST("MAIN_MAIL_EMAIL_FROM", 'alphanohtml')), null, 'errors');
  67. $action = 'edit';
  68. }
  69. if (!$error) {
  70. dolibarr_set_const($db, "MAIN_DISABLE_ALL_MAILS", GETPOST("MAIN_DISABLE_ALL_MAILS", 'int'), 'chaine', 0, '', $conf->entity);
  71. dolibarr_set_const($db, "MAIN_MAIL_FORCE_SENDTO", GETPOST("MAIN_MAIL_FORCE_SENDTO", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
  72. dolibarr_set_const($db, "MAIN_MAIL_ENABLED_USER_DEST_SELECT", GETPOST("MAIN_MAIL_ENABLED_USER_DEST_SELECT", 'int'), 'chaine', 0, '', $conf->entity);
  73. // Send mode parameters
  74. dolibarr_set_const($db, "MAIN_MAIL_SENDMODE", GETPOST("MAIN_MAIL_SENDMODE", 'aZ09'), 'chaine', 0, '', $conf->entity);
  75. dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT", GETPOST("MAIN_MAIL_SMTP_PORT", 'int'), 'chaine', 0, '', $conf->entity);
  76. dolibarr_set_const($db, "MAIN_MAIL_SMTP_SERVER", GETPOST("MAIN_MAIL_SMTP_SERVER", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
  77. dolibarr_set_const($db, "MAIN_MAIL_SMTPS_ID", GETPOST("MAIN_MAIL_SMTPS_ID", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
  78. dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW", GETPOST("MAIN_MAIL_SMTPS_PW", 'none'), 'chaine', 0, '', $conf->entity);
  79. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS", GETPOST("MAIN_MAIL_EMAIL_TLS", 'int'), 'chaine', 0, '', $conf->entity);
  80. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS", GETPOST("MAIN_MAIL_EMAIL_STARTTLS", 'int'), 'chaine', 0, '', $conf->entity);
  81. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED", GETPOST("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED", 'int'), 'chaine', 0, '', $conf->entity);
  82. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_ENABLED", GETPOST("MAIN_MAIL_EMAIL_DKIM_ENABLED", 'int'), 'chaine', 0, '', $conf->entity);
  83. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_DOMAIN", GETPOST("MAIN_MAIL_EMAIL_DKIM_DOMAIN", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
  84. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_SELECTOR", GETPOST("MAIN_MAIL_EMAIL_DKIM_SELECTOR", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
  85. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY", GETPOST("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
  86. // Content parameters
  87. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_FROM", GETPOST("MAIN_MAIL_EMAIL_FROM", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
  88. dolibarr_set_const($db, "MAIN_MAIL_ERRORS_TO", GETPOST("MAIN_MAIL_ERRORS_TO", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
  89. dolibarr_set_const($db, "MAIN_MAIL_AUTOCOPY_TO", GETPOST("MAIN_MAIL_AUTOCOPY_TO", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
  90. dolibarr_set_const($db, 'MAIN_MAIL_DEFAULT_FROMTYPE', GETPOST('MAIN_MAIL_DEFAULT_FROMTYPE', 'alphanohtml'), 'chaine', 0, '', $conf->entity);
  91. header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
  92. exit;
  93. }
  94. }
  95. // Actions to send emails
  96. $id = 0;
  97. $actiontypecode = ''; // Not an event for agenda
  98. $triggersendname = ''; // Disable triggers
  99. $paramname = 'id';
  100. $mode = 'emailfortest';
  101. $trackid = (($action == 'testhtml') ? "testhtml" : "test");
  102. $sendcontext = '';
  103. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  104. if ($action == 'presend' && GETPOST('trackid', 'alphanohtml') == 'test') {
  105. $action = 'test';
  106. }
  107. if ($action == 'presend' && GETPOST('trackid', 'alphanohtml') == 'testhtml') {
  108. $action = 'testhtml';
  109. }
  110. /*
  111. * View
  112. */
  113. $form = new Form($db);
  114. $linuxlike = 1;
  115. if (preg_match('/^win/i', PHP_OS)) {
  116. $linuxlike = 0;
  117. }
  118. if (preg_match('/^mac/i', PHP_OS)) {
  119. $linuxlike = 0;
  120. }
  121. if (empty($conf->global->MAIN_MAIL_SENDMODE)) {
  122. $conf->global->MAIN_MAIL_SENDMODE = 'mail';
  123. }
  124. $port = !empty($conf->global->MAIN_MAIL_SMTP_PORT) ? $conf->global->MAIN_MAIL_SMTP_PORT : ini_get('smtp_port');
  125. if (!$port) {
  126. $port = 25;
  127. }
  128. $server = !empty($conf->global->MAIN_MAIL_SMTP_SERVER) ? $conf->global->MAIN_MAIL_SMTP_SERVER : ini_get('SMTP');
  129. if (!$server) {
  130. $server = '127.0.0.1';
  131. }
  132. $wikihelp = 'EN:Setup_EMails|FR:Paramétrage_EMails|ES:Configuración_EMails';
  133. llxHeader('', $langs->trans("Setup"), $wikihelp);
  134. print load_fiche_titre($langs->trans("EMailsSetup"), '', 'title_setup');
  135. $head = email_admin_prepare_head();
  136. // List of sending methods
  137. $listofmethods = array();
  138. $listofmethods['mail'] = 'PHP mail function';
  139. $listofmethods['smtps'] = 'SMTP/SMTPS socket library';
  140. if (version_compare(phpversion(), '7.0', '>=')) {
  141. $listofmethods['swiftmailer'] = 'Swift Mailer socket library';
  142. }
  143. if ($action == 'edit') {
  144. if ($conf->use_javascript_ajax) {
  145. print "\n".'<script type="text/javascript">';
  146. print 'jQuery(document).ready(function () {
  147. function initfields()
  148. {
  149. if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'mail\')
  150. {
  151. console.log("I choose php mail mode");
  152. jQuery(".drag").hide();
  153. jQuery("#MAIN_MAIL_EMAIL_TLS").val(0);
  154. jQuery("#MAIN_MAIL_EMAIL_TLS").prop("disabled", true);
  155. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val(0);
  156. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").prop("disabled", true);
  157. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val(0);
  158. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").prop("disabled", true);
  159. jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val(0);
  160. jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").prop("disabled", true);
  161. jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").prop("disabled", true);
  162. jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").prop("disabled", true);
  163. jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").prop("disabled", true);
  164. jQuery(".smtp_method").hide();
  165. jQuery(".dkim").hide();
  166. ';
  167. if ($linuxlike) {
  168. print '
  169. jQuery("#MAIN_MAIL_SMTP_SERVER").hide();
  170. jQuery("#MAIN_MAIL_SMTP_PORT").hide();
  171. jQuery("#smtp_server_mess").show();
  172. jQuery("#smtp_port_mess").show();';
  173. } else {
  174. print '
  175. jQuery("#MAIN_MAIL_SMTP_SERVER").prop("disabled", true);
  176. jQuery("#MAIN_MAIL_SMTP_PORT").prop("disabled", true);
  177. jQuery("#smtp_server_mess").hide();
  178. jQuery("#smtp_port_mess").hide();';
  179. }
  180. print '
  181. }
  182. if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'smtps\')
  183. {
  184. console.log("I choose smtps mode");
  185. jQuery(".drag").show();
  186. jQuery("#MAIN_MAIL_EMAIL_TLS").val('.$conf->global->MAIN_MAIL_EMAIL_TLS.');
  187. jQuery("#MAIN_MAIL_EMAIL_TLS").removeAttr("disabled");
  188. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS.');
  189. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").removeAttr("disabled");
  190. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val('.$conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED.');
  191. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").removeAttr("disabled");
  192. jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val(0);
  193. jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").prop("disabled", true);
  194. jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").prop("disabled", true);
  195. jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").prop("disabled", true);
  196. jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").prop("disabled", true);
  197. jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").hide();
  198. jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").hide();
  199. jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").hide();
  200. jQuery("#MAIN_MAIL_SMTP_SERVER").removeAttr("disabled");
  201. jQuery("#MAIN_MAIL_SMTP_PORT").removeAttr("disabled");
  202. jQuery("#MAIN_MAIL_SMTP_SERVER").show();
  203. jQuery("#MAIN_MAIL_SMTP_PORT").show();
  204. jQuery("#smtp_server_mess").hide();
  205. jQuery("#smtp_port_mess").hide();
  206. jQuery(".smtp_method").show();
  207. jQuery(".dkim").hide();
  208. }
  209. if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'swiftmailer\')
  210. {
  211. console.log("I choose swiftmailer mode");
  212. jQuery(".drag").show();
  213. jQuery("#MAIN_MAIL_EMAIL_TLS").val('.$conf->global->MAIN_MAIL_EMAIL_TLS.');
  214. jQuery("#MAIN_MAIL_EMAIL_TLS").removeAttr("disabled");
  215. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS.');
  216. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").removeAttr("disabled");
  217. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val('.$conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED.');
  218. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").removeAttr("disabled");
  219. jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val('.$conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED.');
  220. jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").removeAttr("disabled");
  221. jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").removeAttr("disabled");
  222. jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").removeAttr("disabled");
  223. jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").removeAttr("disabled");
  224. jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").show();
  225. jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").show();
  226. jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").show();
  227. jQuery("#MAIN_MAIL_SMTP_SERVER").removeAttr("disabled");
  228. jQuery("#MAIN_MAIL_SMTP_PORT").removeAttr("disabled");
  229. jQuery("#MAIN_MAIL_SMTP_SERVER").show();
  230. jQuery("#MAIN_MAIL_SMTP_PORT").show();
  231. jQuery("#smtp_server_mess").hide();
  232. jQuery("#smtp_port_mess").hide();
  233. jQuery(".smtp_method").show();
  234. jQuery(".dkim").show();
  235. }
  236. }
  237. initfields();
  238. jQuery("#MAIN_MAIL_SENDMODE").change(function() {
  239. initfields();
  240. });
  241. jQuery("#MAIN_MAIL_EMAIL_TLS").change(function() {
  242. if (jQuery("#MAIN_MAIL_EMAIL_TLS").val() == 1)
  243. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val(0);
  244. else
  245. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val(0);
  246. });
  247. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").change(function() {
  248. if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val() == 1)
  249. jQuery("#MAIN_MAIL_EMAIL_TLS").val(0);
  250. else
  251. jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val(0);
  252. });
  253. })';
  254. print '</script>'."\n";
  255. }
  256. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  257. print '<input type="hidden" name="token" value="'.newToken().'">';
  258. print '<input type="hidden" name="action" value="update">';
  259. print dol_get_fiche_head($head, 'common', '', -1);
  260. print '<span class="opacitymedium">'.$langs->trans("EMailsDesc")."</span><br>\n";
  261. print "<br><br>\n";
  262. clearstatcache();
  263. print '<table class="noborder centpercent">';
  264. print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  265. // Disable
  266. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_MAILS").'</td><td>';
  267. print $form->selectyesno('MAIN_DISABLE_ALL_MAILS', getDolGlobalString('MAIN_DISABLE_ALL_MAILS'), 1);
  268. print '</td></tr>';
  269. // Force e-mail recipient
  270. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_FORCE_SENDTO").'</td><td>';
  271. print '<input class="flat" name="MAIN_MAIL_FORCE_SENDTO" size="32" value="'.(!empty($conf->global->MAIN_MAIL_FORCE_SENDTO) ? $conf->global->MAIN_MAIL_FORCE_SENDTO : '').'" />';
  272. print '</td></tr>';
  273. print '</table>';
  274. print '<br>';
  275. print '<table class="noborder centpercent">';
  276. print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td></td></tr>';
  277. // Method
  278. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
  279. // SuperAdministrator access only
  280. if ((empty($conf->global->MAIN_MODULE_MULTICOMPANY)) || ($user->admin && !$user->entity)) {
  281. print $form->selectarray('MAIN_MAIL_SENDMODE', $listofmethods, $conf->global->MAIN_MAIL_SENDMODE);
  282. } else {
  283. $text = $listofmethods[$conf->global->MAIN_MAIL_SENDMODE];
  284. if (empty($text)) {
  285. $text = $langs->trans("Undefined");
  286. }
  287. $htmltext = $langs->trans("ContactSuperAdminForChange");
  288. print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
  289. print '<input type="hidden" name="MAIN_MAIL_SENDMODE" value="'.$conf->global->MAIN_MAIL_SENDMODE.'">';
  290. }
  291. print '</td></tr>';
  292. // Host server
  293. print '<tr class="oddeven">';
  294. if (!$conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE == 'mail') {
  295. print '<td>';
  296. print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
  297. print '</td><td>';
  298. print '<span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
  299. print '</td>';
  300. } else {
  301. print '<td>';
  302. $mainserver = (!empty($conf->global->MAIN_MAIL_SMTP_SERVER) ? $conf->global->MAIN_MAIL_SMTP_SERVER : '');
  303. $smtpserver = ini_get('SMTP') ?ini_get('SMTP') : $langs->transnoentities("Undefined");
  304. if ($linuxlike) {
  305. print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
  306. } else {
  307. print $langs->trans("MAIN_MAIL_SMTP_SERVER", $smtpserver);
  308. }
  309. print '</td><td>';
  310. // SuperAdministrator access only
  311. if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity)) {
  312. print '<input class="flat minwidth300" id="MAIN_MAIL_SMTP_SERVER" name="MAIN_MAIL_SMTP_SERVER" value="'.$mainserver.'" autocomplete="off">';
  313. print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_sav" name="MAIN_MAIL_SMTP_SERVER_sav" value="'.$mainserver.'">';
  314. print '<span id="smtp_server_mess" class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
  315. print ' <span class="opacitymedium smtp_method">'.$langs->trans("SeeLinkToOnlineDocumentation").'</span>';
  316. } else {
  317. $text = !empty($mainserver) ? $mainserver : $smtpserver;
  318. $htmltext = $langs->trans("ContactSuperAdminForChange");
  319. print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
  320. print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER" name="MAIN_MAIL_SMTP_SERVER" value="'.$mainserver.'">';
  321. }
  322. print '</td>';
  323. }
  324. print '</tr>';
  325. // Port
  326. print '<tr class="oddeven"><td>';
  327. if (!$conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE == 'mail') {
  328. print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
  329. print '</td><td>';
  330. print '<span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
  331. } else {
  332. $mainport = (!empty($conf->global->MAIN_MAIL_SMTP_PORT) ? $conf->global->MAIN_MAIL_SMTP_PORT : '');
  333. $smtpport = ini_get('smtp_port') ?ini_get('smtp_port') : $langs->transnoentities("Undefined");
  334. if ($linuxlike) {
  335. print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
  336. } else {
  337. print $langs->trans("MAIN_MAIL_SMTP_PORT", $smtpport);
  338. }
  339. print '</td><td>';
  340. // SuperAdministrator access only
  341. if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity)) {
  342. print '<input class="flat" id="MAIN_MAIL_SMTP_PORT" name="MAIN_MAIL_SMTP_PORT" size="3" value="'.$mainport.'">';
  343. print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_sav" name="MAIN_MAIL_SMTP_PORT_sav" value="'.$mainport.'">';
  344. print '<span id="smtp_port_mess" class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
  345. } else {
  346. $text = (!empty($mainport) ? $mainport : $smtpport);
  347. $htmltext = $langs->trans("ContactSuperAdminForChange");
  348. print $form->textwithpicto($text, $htmltext, 1, 'superadmin');
  349. print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT" name="MAIN_MAIL_SMTP_PORT" value="'.$mainport.'">';
  350. }
  351. }
  352. print '</td></tr>';
  353. // ID
  354. if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))) {
  355. $mainstmpid = (!empty($conf->global->MAIN_MAIL_SMTPS_ID) ? $conf->global->MAIN_MAIL_SMTPS_ID : '');
  356. print '<tr class="drag drop oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>';
  357. // SuperAdministrator access only
  358. if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity)) {
  359. print '<input class="flat" name="MAIN_MAIL_SMTPS_ID" size="32" value="'.$mainstmpid.'">';
  360. } else {
  361. $htmltext = $langs->trans("ContactSuperAdminForChange");
  362. print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_ID, $htmltext, 1, 'superadmin');
  363. print '<input type="hidden" name="MAIN_MAIL_SMTPS_ID" value="'.$mainstmpid.'">';
  364. }
  365. print '</td></tr>';
  366. }
  367. // PW
  368. if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))) {
  369. $mainsmtppw = (!empty($conf->global->MAIN_MAIL_SMTPS_PW) ? $conf->global->MAIN_MAIL_SMTPS_PW : '');
  370. print '<tr class="drag drop oddeven"><td>';
  371. print $form->textwithpicto($langs->trans("MAIN_MAIL_SMTPS_PW"), $langs->trans("WithGMailYouCanCreateADedicatedPassword"));
  372. print '</td><td>';
  373. // SuperAdministrator access only
  374. if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity)) {
  375. print '<input class="flat" type="password" name="MAIN_MAIL_SMTPS_PW" size="32" value="'.$mainsmtppw.'" autocomplete="off">';
  376. } else {
  377. $htmltext = $langs->trans("ContactSuperAdminForChange");
  378. print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_PW, $htmltext, 1, 'superadmin');
  379. print '<input type="hidden" name="MAIN_MAIL_SMTPS_PW" value="'.$mainsmtppw.'">';
  380. }
  381. print '</td></tr>';
  382. }
  383. // TLS
  384. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
  385. if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))) {
  386. if (function_exists('openssl_open')) {
  387. print $form->selectyesno('MAIN_MAIL_EMAIL_TLS', (!empty($conf->global->MAIN_MAIL_EMAIL_TLS) ? $conf->global->MAIN_MAIL_EMAIL_TLS : 0), 1);
  388. } else {
  389. print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  390. }
  391. } else {
  392. print yn(0).' ('.$langs->trans("NotSupported").')';
  393. }
  394. print '</td></tr>';
  395. // STARTTLS
  396. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
  397. if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))) {
  398. if (function_exists('openssl_open')) {
  399. print $form->selectyesno('MAIN_MAIL_EMAIL_STARTTLS', (!empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS) ? $conf->global->MAIN_MAIL_EMAIL_STARTTLS : 0), 1);
  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. // SMTP_ALLOW_SELF_SIGNED
  408. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").'</td><td>';
  409. if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))) {
  410. if (function_exists('openssl_open')) {
  411. print $form->selectyesno('MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED', (!empty($conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED) ? $conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED : 0), 1);
  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. // DKIM
  420. print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_ENABLED").'</td><td>';
  421. if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('swiftmailer')))) {
  422. if (function_exists('openssl_open')) {
  423. print $form->selectyesno('MAIN_MAIL_EMAIL_DKIM_ENABLED', (!empty($conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED) ? $conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED : 0), 1);
  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. // DKIM Domain
  432. print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_DOMAIN").'</td>';
  433. print '<td><input class="flat" id="MAIN_MAIL_EMAIL_DKIM_DOMAIN" name="MAIN_MAIL_EMAIL_DKIM_DOMAIN" size="32" value="'.(!empty($conf->global->MAIN_MAIL_EMAIL_DKIM_DOMAIN) ? $conf->global->MAIN_MAIL_EMAIL_DKIM_DOMAIN : '');
  434. print '"></td></tr>';
  435. // DKIM Selector
  436. print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_SELECTOR").'</td>';
  437. print '<td><input class="flat" id="MAIN_MAIL_EMAIL_DKIM_SELECTOR" name="MAIN_MAIL_EMAIL_DKIM_SELECTOR" size="32" value="'.(!empty($conf->global->MAIN_MAIL_EMAIL_DKIM_SELECTOR) ? $conf->global->MAIN_MAIL_EMAIL_DKIM_SELECTOR : '');
  438. print '"></td></tr>';
  439. // DKIM PRIVATE KEY
  440. print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").'</td>';
  441. print '<td><textarea id="MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY" name="MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY" rows="15" cols="100">'.(!empty($conf->global->MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY) ? $conf->global->MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY : '').'</textarea>';
  442. print '</td></tr>';
  443. print '</table>';
  444. print '<br>';
  445. print '<table class="noborder centpercent">';
  446. print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("OtherOptions").'</td><td></td></tr>';
  447. // From
  448. $help = img_help(1, $langs->trans("EMailHelpMsgSPFDKIM"));
  449. print '<tr class="oddeven"><td class="fieldrequired">'.$langs->trans("MAIN_MAIL_EMAIL_FROM", ini_get('sendmail_from') ?ini_get('sendmail_from') : $langs->transnoentities("Undefined")).' '.$help.'</td>';
  450. print '<td><input class="flat minwidth200" name="MAIN_MAIL_EMAIL_FROM" value="'.(!empty($conf->global->MAIN_MAIL_EMAIL_FROM) ? $conf->global->MAIN_MAIL_EMAIL_FROM : '');
  451. print '"></td></tr>';
  452. // Default from type
  453. $liste = array();
  454. $liste['user'] = $langs->trans('UserEmail');
  455. $liste['company'] = $langs->trans('CompanyEmail').' ('.(empty($conf->global->MAIN_INFO_SOCIETE_MAIL) ? $langs->trans("NotDefined") : $conf->global->MAIN_INFO_SOCIETE_MAIL).')';
  456. print '<tr class="oddeven"><td>'.$langs->trans('MAIN_MAIL_DEFAULT_FROMTYPE').'</td><td>';
  457. print $form->selectarray('MAIN_MAIL_DEFAULT_FROMTYPE', $liste, getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE'), 0);
  458. print '</td></tr>';
  459. // From
  460. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ERRORS_TO").'</td>';
  461. 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 : '');
  462. print '"></td></tr>';
  463. // Autocopy to
  464. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
  465. 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 : '');
  466. print '"></td></tr>';
  467. // Add user to select destinaries list
  468. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ENABLED_USER_DEST_SELECT").'</td><td>';
  469. print $form->selectyesno('MAIN_MAIL_ENABLED_USER_DEST_SELECT', getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT'), 1);
  470. print '</td></tr>';
  471. print '</table>';
  472. print dol_get_fiche_end();
  473. print $form->buttonsSaveCancel();
  474. print '</form>';
  475. } else {
  476. print dol_get_fiche_head($head, 'common', '', -1);
  477. print '<span class="opacitymedium">'.$langs->trans("EMailsDesc")."</span><br>\n";
  478. print "<br><br>\n";
  479. 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
  480. print '<table class="noborder centpercent">';
  481. print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  482. // Disable
  483. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_MAILS").'</td><td>'.yn(!empty($conf->global->MAIN_DISABLE_ALL_MAILS));
  484. if (!empty($conf->global->MAIN_DISABLE_ALL_MAILS)) {
  485. print img_warning($langs->trans("Disabled"));
  486. }
  487. print '</td></tr>';
  488. if (empty($conf->global->MAIN_DISABLE_ALL_MAILS)) {
  489. // Force e-mail recipient
  490. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_FORCE_SENDTO").'</td><td>'.getDolGlobalString('MAIN_MAIL_FORCE_SENDTO');
  491. if (!empty(getDolGlobalString('MAIN_MAIL_FORCE_SENDTO'))) {
  492. if (!isValidEmail(getDolGlobalString('MAIN_MAIL_FORCE_SENDTO'))) {
  493. print img_warning($langs->trans("ErrorBadEMail"));
  494. } else {
  495. print img_warning($langs->trans("RecipientEmailsWillBeReplacedWithThisValue"));
  496. }
  497. }
  498. print '</td></tr>';
  499. }
  500. print '</table>';
  501. print '</div>';
  502. if (empty($conf->global->MAIN_DISABLE_ALL_MAILS)) {
  503. print '<br>';
  504. 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
  505. print '<table class="noborder centpercent">';
  506. print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td></td></tr>';
  507. // Method
  508. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
  509. $text = $listofmethods[$conf->global->MAIN_MAIL_SENDMODE];
  510. if (empty($text)) {
  511. $text = $langs->trans("Undefined").img_warning();
  512. }
  513. print $text;
  514. if ($conf->global->MAIN_MAIL_SENDMODE == 'mail' && empty($conf->global->MAIN_HIDE_WARNING_TO_ENCOURAGE_SMTP_SETUP)) {
  515. print $form->textwithpicto('', $langs->trans("WarningPHPMail").'<br>'.$langs->trans("WarningPHPMailA").'<br>'.$langs->trans("WarningPHPMailB").'<br>'.$langs->trans("WarningPHPMailC").'<br><br>'.$langs->trans("WarningPHPMailD"), 1, 'warning');
  516. }
  517. print '</td></tr>';
  518. // Host server
  519. if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'mail')) {
  520. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike").'</td><td><span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span></td></tr>';
  521. } else {
  522. 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>';
  523. }
  524. // Port
  525. if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'mail')) {
  526. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").'</td><td><span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span></td></tr>';
  527. } else {
  528. 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>';
  529. }
  530. // SMTPS ID
  531. if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))) {
  532. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>'.$conf->global->MAIN_MAIL_SMTPS_ID.'</td></tr>';
  533. }
  534. // SMTPS PW
  535. if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))) {
  536. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>'.preg_replace('/./', '*', $conf->global->MAIN_MAIL_SMTPS_PW).'</td></tr>';
  537. }
  538. // TLS
  539. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
  540. if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))) {
  541. if (function_exists('openssl_open')) {
  542. print yn($conf->global->MAIN_MAIL_EMAIL_TLS);
  543. } else {
  544. print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  545. }
  546. } else {
  547. print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
  548. }
  549. print '</td></tr>';
  550. // STARTTLS
  551. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
  552. if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))) {
  553. if (function_exists('openssl_open')) {
  554. print yn($conf->global->MAIN_MAIL_EMAIL_STARTTLS);
  555. } else {
  556. print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  557. }
  558. } else {
  559. print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
  560. }
  561. print '</td></tr>';
  562. // SMTP_ALLOW_SELF_SIGNED
  563. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").'</td><td>';
  564. if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))) {
  565. if (function_exists('openssl_open')) {
  566. print yn($conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED);
  567. } else {
  568. print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  569. }
  570. } else {
  571. print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
  572. }
  573. print '</td></tr>';
  574. if ($conf->global->MAIN_MAIL_SENDMODE == 'swiftmailer') {
  575. // DKIM
  576. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_ENABLED").'</td><td>';
  577. if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('swiftmailer'))) {
  578. if (function_exists('openssl_open')) {
  579. print yn(getDolGlobalInt('MAIN_MAIL_EMAIL_DKIM_ENABLED'));
  580. } else {
  581. print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  582. }
  583. } else {
  584. print yn(0).' ('.$langs->trans("NotSupported").')';
  585. }
  586. print '</td></tr>';
  587. // Domain
  588. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_DOMAIN").'</td>';
  589. print '<td>'.getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_DOMAIN');
  590. print '</td></tr>';
  591. // Selector
  592. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_SELECTOR").'</td>';
  593. print '<td>'.getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_SELECTOR');
  594. print '</td></tr>';
  595. // PRIVATE KEY
  596. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").'</td>';
  597. print '<td>'.getDolGlobalString('MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY');
  598. print '</td></tr>';
  599. }
  600. print '</table>';
  601. print '</div>';
  602. if ($conf->global->MAIN_MAIL_SENDMODE == 'mail' && empty($conf->global->MAIN_HIDE_WARNING_TO_ENCOURAGE_SMTP_SETUP)) {
  603. print info_admin($langs->trans("WarningPHPMail").'<br>'.$langs->trans("WarningPHPMailA").'<br>'.$langs->trans("WarningPHPMailB").'<br>'.$langs->trans("WarningPHPMailC").'<br><br>'.$langs->trans("WarningPHPMailD"), 0, 0, 'warning');
  604. }
  605. print '<br>';
  606. 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
  607. print '<table class="noborder centpercent">';
  608. print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("OtherOptions").'</td><td></td></tr>';
  609. // From
  610. $help = img_help(1, $langs->trans("EMailHelpMsgSPFDKIM"));
  611. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_FROM", ini_get('sendmail_from') ?ini_get('sendmail_from') : $langs->transnoentities("Undefined")).' '.$help.'</td>';
  612. print '<td>'.$conf->global->MAIN_MAIL_EMAIL_FROM;
  613. if (empty($conf->global->MAIN_MAIL_EMAIL_FROM)) {
  614. print img_warning($langs->trans("Mandatory"));
  615. } elseif (!isValidEmail($conf->global->MAIN_MAIL_EMAIL_FROM)) {
  616. print img_warning($langs->trans("ErrorBadEMail"));
  617. }
  618. print '</td></tr>';
  619. // Default from type
  620. $liste = array();
  621. $liste['user'] = $langs->trans('UserEmail');
  622. $liste['company'] = $langs->trans('CompanyEmail').' ('.(empty($conf->global->MAIN_INFO_SOCIETE_MAIL) ? $langs->trans("NotDefined") : $conf->global->MAIN_INFO_SOCIETE_MAIL).')';
  623. $sql = 'SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile';
  624. $sql .= ' WHERE active = 1 AND (private = 0 OR private = '.((int) $user->id).')';
  625. $resql = $db->query($sql);
  626. if ($resql) {
  627. $num = $db->num_rows($resql);
  628. $i = 0;
  629. while ($i < $num) {
  630. $obj = $db->fetch_object($resql);
  631. if ($obj) {
  632. $liste['senderprofile_'.$obj->rowid] = $obj->label.' <'.$obj->email.'>';
  633. }
  634. $i++;
  635. }
  636. } else {
  637. dol_print_error($db);
  638. }
  639. print '<tr class="oddeven"><td>'.$langs->trans('MAIN_MAIL_DEFAULT_FROMTYPE').'</td>';
  640. print '<td>';
  641. if (getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE') === 'robot') {
  642. print $langs->trans('RobotEmail');
  643. } elseif (getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE') === 'user') {
  644. print $langs->trans('UserEmail');
  645. } elseif (getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE') === 'company') {
  646. print $langs->trans('CompanyEmail').' '.dol_escape_htmltag('<'.$mysoc->email.'>');
  647. } else {
  648. $id = preg_replace('/senderprofile_/', '', getDolGlobalString('MAIN_MAIL_DEFAULT_FROMTYPE'));
  649. if ($id > 0) {
  650. include_once DOL_DOCUMENT_ROOT.'/core/class/emailsenderprofile.class.php';
  651. $emailsenderprofile = new EmailSenderProfile($db);
  652. $emailsenderprofile->fetch($id);
  653. print $emailsenderprofile->label.' '.dol_escape_htmltag('<'.$emailsenderprofile->email.'>');
  654. }
  655. }
  656. print '</td></tr>';
  657. // Errors To
  658. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ERRORS_TO").'</td>';
  659. print '<td>'.(getDolGlobalString('MAIN_MAIL_ERRORS_TO'));
  660. if (!empty($conf->global->MAIN_MAIL_ERRORS_TO) && !isValidEmail($conf->global->MAIN_MAIL_ERRORS_TO)) {
  661. print img_warning($langs->trans("ErrorBadEMail"));
  662. }
  663. print '</td></tr>';
  664. // Autocopy to
  665. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
  666. print '<td>';
  667. if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) {
  668. $listofemail = explode(',', $conf->global->MAIN_MAIL_AUTOCOPY_TO);
  669. $i = 0;
  670. foreach ($listofemail as $key => $val) {
  671. if ($i) {
  672. print ', ';
  673. }
  674. $val = trim($val);
  675. print $val;
  676. if (!isValidEmail($val, 0, 1)) {
  677. print img_warning($langs->trans("ErrorBadEMail", $val));
  678. }
  679. $i++;
  680. }
  681. } else {
  682. print '&nbsp;';
  683. }
  684. print '</td></tr>';
  685. //Add user to select destinaries list
  686. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ENABLED_USER_DEST_SELECT").'</td><td>'.yn(!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)).'</td></tr>';
  687. print '</table>';
  688. print '</div>';
  689. }
  690. print dol_get_fiche_end();
  691. // Actions button
  692. print '<div class="tabsAction">';
  693. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
  694. if (empty($conf->global->MAIN_DISABLE_ALL_MAILS)) {
  695. if ($conf->global->MAIN_MAIL_SENDMODE != 'mail' || !$linuxlike) {
  696. if (function_exists('fsockopen') && $port && $server) {
  697. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect&date='.dol_now().'#formmailaftertstconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
  698. }
  699. } else {
  700. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
  701. }
  702. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&mode=init#formmailbeforetitle">'.$langs->trans("DoTestSend").'</a>';
  703. if (!empty($conf->fckeditor->enabled)) {
  704. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testhtml&mode=init#formmailbeforetitle">'.$langs->trans("DoTestSendHTML").'</a>';
  705. }
  706. }
  707. print '</div>';
  708. if ($conf->global->MAIN_MAIL_SENDMODE == 'mail' && empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)) {
  709. /*
  710. // Warning 1
  711. if ($linuxlike)
  712. {
  713. $sendmailoption=ini_get('mail.force_extra_parameters');
  714. if (empty($sendmailoption) || ! preg_match('/ba/',$sendmailoption))
  715. {
  716. print info_admin($langs->trans("SendmailOptionNotComplete"));
  717. }
  718. }*/
  719. // Warning 2
  720. print info_admin($langs->trans("SendmailOptionMayHurtBuggedMTA"));
  721. }
  722. if (!in_array($action, array('testconnect', 'test', 'testhtml'))) {
  723. $text = '';
  724. if ($conf->global->MAIN_MAIL_SENDMODE == 'mail') {
  725. //$text .= $langs->trans("WarningPHPMail"); // To encourage to use SMTPS
  726. }
  727. if ($conf->global->MAIN_MAIL_SENDMODE == 'mail') {
  728. if (!empty($conf->global->MAIN_EXTERNAL_MAIL_SPF_STRING_TO_ADD)) {
  729. // List of string to add in SPF if the setup use the mail method. Example 'include:sendgrid.net include:spf.mydomain.com'
  730. $text .= ($text ? '<br><br>' : '').'<!-- MAIN_EXTERNAL_MAIL_SPF_STRING_TO_ADD -->'.$langs->trans("WarningPHPMailSPF", $conf->global->MAIN_EXTERNAL_MAIL_SPF_STRING_TO_ADD);
  731. } else {
  732. // MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS is list of IPs where email is sent from. Example: '1.2.3.4, [aaaa:bbbb:cccc:dddd]'.
  733. if (!empty($conf->global->MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS)) {
  734. // List of IP show as record to add in SPF if we use the mail method
  735. $text .= ($text ? '<br><br>' : '').'<!-- MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS -->'.$langs->trans("WarningPHPMailSPF", $conf->global->MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS);
  736. }
  737. }
  738. } else {
  739. if (!empty($conf->global->MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS)) {
  740. // List of IP show as record to add as allowed IP if we use the smtp method. Value is '1.2.3.4, [aaaa:bbbb:cccc:dddd]'
  741. // TODO Add a key to allow to show the IP/name of server detected dynamically
  742. $text .= ($text ? '<br><br>' : '').'<!-- MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS -->'.$langs->trans("WarningPHPMail2", $conf->global->MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS);
  743. }
  744. if (!empty($conf->global->MAIN_EXTERNAL_SMTP_SPF_STRING_TO_ADD)) { // Should be required only if you have preset the Dolibarr to use your own SMTP and you want to warn users to update their domain name to match your SMTP server.
  745. // List of string to add in SPF if we use the smtp method. Example 'include:spf.mydomain.com'
  746. $text .= ($text ? '<br><br>' : '').'<!-- MAIN_EXTERNAL_SMTP_SPF_STRING_TO_ADD -->'.$langs->trans("WarningPHPMailSPF", $conf->global->MAIN_EXTERNAL_SMTP_SPF_STRING_TO_ADD);
  747. }
  748. }
  749. $companyemail = getDolGlobalString('MAIN_INFO_SOCIETE_MAIL');
  750. $dnsinfo = false;
  751. if (!empty($companyemail) && function_exists('dns_get_record')) {
  752. $arrayofemailparts = explode('@', $companyemail);
  753. if (count($arrayofemailparts) == 2) {
  754. $domain = $arrayofemailparts[1];
  755. $dnsinfo = dns_get_record($domain, DNS_TXT);
  756. }
  757. }
  758. if (!empty($dnsinfo) && is_array($dnsinfo)) {
  759. foreach ($dnsinfo as $info) {
  760. if (strpos($info['txt'], 'v=spf') !== false) {
  761. $text .= ($text ? '<br><br>' : '').$langs->trans("ActualMailSPFRecordFound", $companyemail, $info['txt']);
  762. }
  763. }
  764. }
  765. if ($text) {
  766. print info_admin($text);
  767. }
  768. }
  769. // Run the test to connect
  770. if ($action == 'testconnect') {
  771. print '<div id="formmailaftertstconnect" name="formmailaftertstconnect"></div>';
  772. print load_fiche_titre($langs->trans("DoTestServerAvailability"));
  773. include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  774. $mail = new CMailFile('', '', '', '', array(), array(), array(), '', '', 0, '', '', '', '', $trackid, $sendcontext);
  775. $result = $mail->check_server_port($server, $port);
  776. if ($result) {
  777. print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort", $server, $port).'</div>';
  778. } else {
  779. $errormsg = $langs->trans("ServerNotAvailableOnIPOrPort", $server, $port);
  780. if ($mail->error) {
  781. $errormsg .= ' - '.$mail->error;
  782. }
  783. setEventMessages($errormsg, null, 'errors');
  784. }
  785. print '<br>';
  786. }
  787. // Show email send test form
  788. if ($action == 'test' || $action == 'testhtml') {
  789. print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
  790. print load_fiche_titre($action == 'testhtml' ? $langs->trans("DoTestSendHTML") : $langs->trans("DoTestSend"));
  791. print dol_get_fiche_head('');
  792. // Cree l'objet formulaire mail
  793. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  794. $formmail = new FormMail($db);
  795. $formmail->trackid = (($action == 'testhtml') ? "testhtml" : "test");
  796. $formmail->fromname = (GETPOSTISSET('fromname') ? GETPOST('fromname') : $conf->global->MAIN_MAIL_EMAIL_FROM);
  797. $formmail->frommail = (GETPOSTISSET('frommail') ? GETPOST('frommail') : $conf->global->MAIN_MAIL_EMAIL_FROM);
  798. $formmail->fromid = $user->id;
  799. $formmail->fromalsorobot = 1;
  800. $formmail->fromtype = (GETPOSTISSET('fromtype') ?GETPOST('fromtype', 'aZ09') : (!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE) ? $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE : 'user'));
  801. $formmail->withfromreadonly = 1;
  802. $formmail->withsubstit = 1;
  803. $formmail->withfrom = 1;
  804. $formmail->witherrorsto = 1;
  805. $formmail->withto = (GETPOSTISSET('sendto') ? GETPOST('sendto', 'restricthtml') : ($user->email ? $user->email : 1));
  806. $formmail->withtocc = (GETPOSTISSET('sendtocc') ? GETPOST('sendtocc', 'restricthtml') : 1); // ! empty to keep field if empty
  807. $formmail->withtoccc = (GETPOSTISSET('sendtoccc') ? GETPOST('sendtoccc', 'restricthtml') : 1); // ! empty to keep field if empty
  808. $formmail->withtopic = (GETPOSTISSET('subject') ? GETPOST('subject') : $langs->trans("Test"));
  809. $formmail->withtopicreadonly = 0;
  810. $formmail->withfile = 2;
  811. $formmail->withbody = (GETPOSTISSET('message') ? GETPOST('message', 'restricthtml') : ($action == 'testhtml' ? $langs->transnoentities("PredefinedMailTestHtml") : $langs->transnoentities("PredefinedMailTest")));
  812. $formmail->withbodyreadonly = 0;
  813. $formmail->withcancel = 1;
  814. $formmail->withdeliveryreceipt = 1;
  815. $formmail->withfckeditor = ($action == 'testhtml' ? 1 : 0);
  816. $formmail->ckeditortoolbar = 'dolibarr_mailings';
  817. // Tableau des substitutions
  818. $formmail->substit = $substitutionarrayfortest;
  819. // Tableau des parametres complementaires du post
  820. $formmail->param["action"] = "send";
  821. $formmail->param["models"] = "body";
  822. $formmail->param["mailid"] = 0;
  823. $formmail->param["returnurl"] = $_SERVER["PHP_SELF"];
  824. // Init list of files
  825. if (GETPOST("mode", "aZ09") == 'init') {
  826. $formmail->clear_attached_files();
  827. }
  828. print $formmail->get_form('addfile', 'removefile');
  829. print dol_get_fiche_end();
  830. // References
  831. print '<span class="opacitymedium">'.$langs->trans("EMailsWillHaveMessageID").': ';
  832. print dol_escape_htmltag('<timestamp.*@'.dol_getprefix('email').'>');
  833. print '</span>';
  834. }
  835. }
  836. // End of page
  837. llxFooter();
  838. $db->close();