mails_emailing.php 36 KB

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