mails.php 52 KB

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