mails.php 54 KB

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