mails.php 52 KB

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