mails_emailing.php 36 KB

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