mails_emailing.php 36 KB

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