mails.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. <?php
  2. /* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2016 Jonathan TISSEAU <jonathan.tisseau@86dev.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/admin/mails.php
  22. * \brief Page to setup emails sending
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  27. // Load translation files required by the page
  28. $langs->loadLangs(array("companies", "products", "admin", "mails", "other", "errors"));
  29. $action=GETPOST('action','alpha');
  30. if (! $user->admin) accessforbidden();
  31. $usersignature=$user->signature;
  32. // For action = test or send, we ensure that content is not html, even for signature, because this we want a test with NO html.
  33. if ($action == 'test' || $action == 'send')
  34. {
  35. $usersignature=dol_string_nohtmltag($usersignature);
  36. }
  37. $substitutionarrayfortest=array(
  38. '__DOL_MAIN_URL_ROOT__'=>DOL_MAIN_URL_ROOT,
  39. '__ID__' => 'RecipientIdRecord',
  40. //'__EMAIL__' => 'RecipientEMail', // Done into actions_sendmails
  41. '__CHECK_READ__' => (is_object($object) && is_object($object->thirdparty))?'<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$object->thirdparty->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>':'',
  42. '__USER_SIGNATURE__' => (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))?$usersignature:''), // Done into actions_sendmails
  43. '__LOGIN__' => 'RecipientLogin',
  44. '__LASTNAME__' => 'RecipientLastname',
  45. '__FIRSTNAME__' => 'RecipientFirstname',
  46. '__ADDRESS__'=> 'RecipientAddress',
  47. '__ZIP__'=> 'RecipientZip',
  48. '__TOWN_'=> 'RecipientTown',
  49. '__COUNTRY__'=> 'RecipientCountry'
  50. );
  51. complete_substitutions_array($substitutionarrayfortest, $langs);
  52. /*
  53. * Actions
  54. */
  55. if ($action == 'update' && empty($_POST["cancel"]))
  56. {
  57. dolibarr_set_const($db, "MAIN_DISABLE_ALL_MAILS", GETPOST("MAIN_DISABLE_ALL_MAILS"), 'chaine', 0, '', $conf->entity);
  58. dolibarr_set_const($db, "MAIN_MAIL_FORCE_SENDTO", GETPOST("MAIN_MAIL_FORCE_SENDTO"), 'chaine', 0, '', $conf->entity);
  59. dolibarr_set_const($db, "MAIN_MAIL_ENABLED_USER_DEST_SELECT", GETPOST("MAIN_MAIL_ENABLED_USER_DEST_SELECT"), 'chaine', 0, '', $conf->entity);
  60. // Send mode parameters
  61. dolibarr_set_const($db, "MAIN_MAIL_SENDMODE", GETPOST("MAIN_MAIL_SENDMODE"), 'chaine', 0, '', $conf->entity);
  62. dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT", GETPOST("MAIN_MAIL_SMTP_PORT"), 'chaine', 0, '', $conf->entity);
  63. dolibarr_set_const($db, "MAIN_MAIL_SMTP_SERVER", GETPOST("MAIN_MAIL_SMTP_SERVER"), 'chaine', 0, '', $conf->entity);
  64. dolibarr_set_const($db, "MAIN_MAIL_SMTPS_ID", GETPOST("MAIN_MAIL_SMTPS_ID"), 'chaine', 0, '', $conf->entity);
  65. dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW", GETPOST("MAIN_MAIL_SMTPS_PW"), 'chaine', 0, '', $conf->entity);
  66. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS", GETPOST("MAIN_MAIL_EMAIL_TLS"), 'chaine', 0, '', $conf->entity);
  67. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS", GETPOST("MAIN_MAIL_EMAIL_STARTTLS"), 'chaine', 0, '', $conf->entity);
  68. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_ENABLED", GETPOST("MAIN_MAIL_EMAIL_DKIM_ENABLED"), 'chaine', 0, '', $conf->entity);
  69. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_DOMAIN", GETPOST("MAIN_MAIL_EMAIL_DKIM_DOMAIN"), 'chaine', 0, '', $conf->entity);
  70. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_SELECTOR", GETPOST("MAIN_MAIL_EMAIL_DKIM_SELECTOR"), 'chaine', 0, '', $conf->entity);
  71. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY", GETPOST("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY"), 'chaine', 0, '', $conf->entity);
  72. // Content parameters
  73. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_FROM", GETPOST("MAIN_MAIL_EMAIL_FROM"), 'chaine', 0, '', $conf->entity);
  74. dolibarr_set_const($db, "MAIN_MAIL_ERRORS_TO", GETPOST("MAIN_MAIL_ERRORS_TO"), 'chaine', 0, '', $conf->entity);
  75. dolibarr_set_const($db, "MAIN_MAIL_AUTOCOPY_TO", GETPOST("MAIN_MAIL_AUTOCOPY_TO"),'chaine', 0, '', $conf->entity);
  76. dolibarr_set_const($db, 'MAIN_MAIL_DEFAULT_FROMTYPE', GETPOST('MAIN_MAIL_DEFAULT_FROMTYPE'), 'chaine', 0, '', $conf->entity);
  77. header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
  78. exit;
  79. }
  80. // Actions to send emails
  81. $id=0;
  82. $actiontypecode=''; // Not an event for agenda
  83. $trigger_name=''; // Disable triggers
  84. $paramname='id';
  85. $mode='emailfortest';
  86. $trackid=(($action == 'testhtml')?"testhtml":"test");
  87. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  88. if ($action == 'presend' && GETPOST('trackid') == 'test') $action='test';
  89. if ($action == 'presend' && GETPOST('trackid') == 'testhtml') $action='testhtml';
  90. /*
  91. * View
  92. */
  93. $linuxlike=1;
  94. if (preg_match('/^win/i',PHP_OS)) $linuxlike=0;
  95. if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0;
  96. if (empty($conf->global->MAIN_MAIL_SENDMODE)) $conf->global->MAIN_MAIL_SENDMODE='mail';
  97. $port=! empty($conf->global->MAIN_MAIL_SMTP_PORT)?$conf->global->MAIN_MAIL_SMTP_PORT:ini_get('smtp_port');
  98. if (! $port) $port=25;
  99. $server=! empty($conf->global->MAIN_MAIL_SMTP_SERVER)?$conf->global->MAIN_MAIL_SMTP_SERVER:ini_get('SMTP');
  100. if (! $server) $server='127.0.0.1';
  101. $wikihelp='EN:Setup_EMails|FR:Paramétrage_EMails|ES:Configuración_EMails';
  102. llxHeader('',$langs->trans("Setup"),$wikihelp);
  103. print load_fiche_titre($langs->trans("EMailsSetup"),'','title_setup');
  104. $head = email_admin_prepare_head();
  105. // List of sending methods
  106. $listofmethods=array();
  107. $listofmethods['mail']='PHP mail function';
  108. //$listofmethods['simplemail']='Simplemail class';
  109. $listofmethods['smtps']='SMTP/SMTPS socket library';
  110. $listofmethods['swiftmailer']='Swift Mailer socket library';
  111. if ($action == 'edit')
  112. {
  113. $form=new Form($db);
  114. if ($conf->use_javascript_ajax)
  115. {
  116. print "\n".'<script type="text/javascript" language="javascript">';
  117. print 'jQuery(document).ready(function () {
  118. function initfields()
  119. {
  120. if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'mail\')
  121. {
  122. console.log("I choose php mail mode");
  123. jQuery(".drag").hide();
  124. jQuery("#MAIN_MAIL_EMAIL_TLS").val(0);
  125. jQuery("#MAIN_MAIL_EMAIL_TLS").prop("disabled", true);
  126. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val(0);
  127. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").prop("disabled", true);
  128. jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val(0);
  129. jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").prop("disabled", true);
  130. jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").prop("disabled", true);
  131. jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").prop("disabled", true);
  132. jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").prop("disabled", true);
  133. jQuery(".dkim").hide();
  134. ';
  135. if ($linuxlike)
  136. {
  137. print '
  138. jQuery("#MAIN_MAIL_SMTP_SERVER").hide();
  139. jQuery("#MAIN_MAIL_SMTP_PORT").hide();
  140. jQuery("#smtp_server_mess").show();
  141. jQuery("#smtp_port_mess").show();';
  142. }
  143. else
  144. {
  145. print '
  146. jQuery("#MAIN_MAIL_SMTP_SERVER").prop("disabled", true);
  147. jQuery("#MAIN_MAIL_SMTP_PORT").prop("disabled", true);
  148. jQuery("#smtp_server_mess").hide();
  149. jQuery("#smtp_port_mess").hide();';
  150. }
  151. print '
  152. }
  153. if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'smtps\')
  154. {
  155. console.log("I choose smtps mode");
  156. jQuery(".drag").show();
  157. jQuery("#MAIN_MAIL_EMAIL_TLS").val('.$conf->global->MAIN_MAIL_EMAIL_TLS.');
  158. jQuery("#MAIN_MAIL_EMAIL_TLS").removeAttr("disabled");
  159. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS.');
  160. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").removeAttr("disabled");
  161. jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val(0);
  162. jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").prop("disabled", true);
  163. jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").prop("disabled", true);
  164. jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").prop("disabled", true);
  165. jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").prop("disabled", true);
  166. jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").hide();
  167. jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").hide();
  168. jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").hide();
  169. jQuery("#MAIN_MAIL_SMTP_SERVER").removeAttr("disabled");
  170. jQuery("#MAIN_MAIL_SMTP_PORT").removeAttr("disabled");
  171. jQuery("#MAIN_MAIL_SMTP_SERVER").show();
  172. jQuery("#MAIN_MAIL_SMTP_PORT").show();
  173. jQuery("#smtp_server_mess").hide();
  174. jQuery("#smtp_port_mess").hide();
  175. jQuery(".dkim").hide();
  176. }
  177. if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'swiftmailer\')
  178. {
  179. console.log("I choose swiftmailer mode");
  180. jQuery(".drag").show();
  181. jQuery("#MAIN_MAIL_EMAIL_TLS").val('.$conf->global->MAIN_MAIL_EMAIL_TLS.');
  182. jQuery("#MAIN_MAIL_EMAIL_TLS").removeAttr("disabled");
  183. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS.');
  184. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").removeAttr("disabled");
  185. jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val('.$conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED.');
  186. jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").removeAttr("disabled");
  187. jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").removeAttr("disabled");
  188. jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").removeAttr("disabled");
  189. jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").removeAttr("disabled");
  190. jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").show();
  191. jQuery("#MAIN_MAIL_EMAIL_DKIM_SELECTOR").show();
  192. jQuery("#MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").show();
  193. jQuery("#MAIN_MAIL_SMTP_SERVER").removeAttr("disabled");
  194. jQuery("#MAIN_MAIL_SMTP_PORT").removeAttr("disabled");
  195. jQuery("#MAIN_MAIL_SMTP_SERVER").show();
  196. jQuery("#MAIN_MAIL_SMTP_PORT").show();
  197. jQuery("#smtp_server_mess").hide();
  198. jQuery("#smtp_port_mess").hide();
  199. jQuery(".dkim").show();
  200. }
  201. }
  202. initfields();
  203. jQuery("#MAIN_MAIL_SENDMODE").change(function() {
  204. initfields();
  205. });
  206. jQuery("#MAIN_MAIL_EMAIL_TLS").change(function() {
  207. if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val() == 1)
  208. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val(0);
  209. });
  210. jQuery("#MAIN_MAIL_EMAIL_STARTTLS").change(function() {
  211. if (jQuery("#MAIN_MAIL_EMAIL_TLS").val() == 1)
  212. jQuery("#MAIN_MAIL_EMAIL_TLS").val(0);
  213. });
  214. })';
  215. print '</script>'."\n";
  216. }
  217. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  218. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  219. print '<input type="hidden" name="action" value="update">';
  220. dol_fiche_head($head, 'common', '', -1);
  221. print $langs->trans("EMailsDesc")."<br>\n";
  222. print "<br>\n";
  223. clearstatcache();
  224. print '<table class="noborder" width="100%">';
  225. print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  226. // Disable
  227. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_MAILS").'</td><td>';
  228. print $form->selectyesno('MAIN_DISABLE_ALL_MAILS',$conf->global->MAIN_DISABLE_ALL_MAILS,1);
  229. print '</td></tr>';
  230. // Force e-mail recipient
  231. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_FORCE_SENDTO").'</td><td>';
  232. print '<input class="flat" name="MAIN_MAIL_FORCE_SENDTO" size="32" value="' . (! empty($conf->global->MAIN_MAIL_FORCE_SENDTO)?$conf->global->MAIN_MAIL_FORCE_SENDTO:'') . '" />';
  233. print '</td></tr>';
  234. //Add user to select destinaries list
  235. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ENABLED_USER_DEST_SELECT").'</td><td>';
  236. print $form->selectyesno('MAIN_MAIL_ENABLED_USER_DEST_SELECT',$conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT,1);
  237. print '</td></tr>';
  238. // Separator
  239. print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
  240. // Method
  241. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
  242. // SuperAdministrator access only
  243. if ((empty($conf->global->MAIN_MODULE_MULTICOMPANY)) || ($user->admin && !$user->entity))
  244. {
  245. print $form->selectarray('MAIN_MAIL_SENDMODE',$listofmethods,$conf->global->MAIN_MAIL_SENDMODE);
  246. }
  247. else
  248. {
  249. $text = $listofmethods[$conf->global->MAIN_MAIL_SENDMODE];
  250. if (empty($text)) $text = $langs->trans("Undefined");
  251. $htmltext = $langs->trans("ContactSuperAdminForChange");
  252. print $form->textwithpicto($text,$htmltext,1,'superadmin');
  253. print '<input type="hidden" name="MAIN_MAIL_SENDMODE" value="'.$conf->global->MAIN_MAIL_SENDMODE.'">';
  254. }
  255. print '</td></tr>';
  256. // Host server
  257. print '<tr class="oddeven"><td>';
  258. if (! $conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE == 'mail')
  259. {
  260. print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
  261. print '</td><td>';
  262. print '<span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
  263. }
  264. else
  265. {
  266. $mainserver = (! empty($conf->global->MAIN_MAIL_SMTP_SERVER)?$conf->global->MAIN_MAIL_SMTP_SERVER:'');
  267. $smtpserver = ini_get('SMTP')?ini_get('SMTP'):$langs->transnoentities("Undefined");
  268. if ($linuxlike) print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
  269. else print $langs->trans("MAIN_MAIL_SMTP_SERVER",$smtpserver);
  270. print '</td><td>';
  271. // SuperAdministrator access only
  272. if (empty($conf->multicompany->enabled) || ($user->admin && ! $user->entity))
  273. {
  274. print '<input class="flat" id="MAIN_MAIL_SMTP_SERVER" name="MAIN_MAIL_SMTP_SERVER" size="18" value="' . $mainserver . '">';
  275. print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_sav" name="MAIN_MAIL_SMTP_SERVER_sav" value="' . $mainserver . '">';
  276. print '<span id="smtp_server_mess" class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
  277. }
  278. else
  279. {
  280. $text = ! empty($mainserver) ? $mainserver : $smtpserver;
  281. $htmltext = $langs->trans("ContactSuperAdminForChange");
  282. print $form->textwithpicto($text,$htmltext,1,'superadmin');
  283. print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER" name="MAIN_MAIL_SMTP_SERVER" value="'.$mainserver.'">';
  284. }
  285. }
  286. print '</td></tr>';
  287. // Port
  288. print '<tr class="oddeven"><td>';
  289. if (! $conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE == 'mail')
  290. {
  291. print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
  292. print '</td><td>';
  293. print '<span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
  294. }
  295. else
  296. {
  297. $mainport = (! empty($conf->global->MAIN_MAIL_SMTP_PORT) ? $conf->global->MAIN_MAIL_SMTP_PORT : '');
  298. $smtpport = ini_get('smtp_port')?ini_get('smtp_port'):$langs->transnoentities("Undefined");
  299. if ($linuxlike) print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
  300. else print $langs->trans("MAIN_MAIL_SMTP_PORT",$smtpport);
  301. print '</td><td>';
  302. // SuperAdministrator access only
  303. if (empty($conf->multicompany->enabled) || ($user->admin && ! $user->entity))
  304. {
  305. print '<input class="flat" id="MAIN_MAIL_SMTP_PORT" name="MAIN_MAIL_SMTP_PORT" size="3" value="' . $mainport . '">';
  306. print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_sav" name="MAIN_MAIL_SMTP_PORT_sav" value="' . $mainport . '">';
  307. print '<span id="smtp_port_mess" class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
  308. }
  309. else
  310. {
  311. $text = (! empty($mainport) ? $mainport : $smtpport);
  312. $htmltext = $langs->trans("ContactSuperAdminForChange");
  313. print $form->textwithpicto($text,$htmltext,1,'superadmin');
  314. print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT" name="MAIN_MAIL_SMTP_PORT" value="'.$mainport.'">';
  315. }
  316. }
  317. print '</td></tr>';
  318. // ID
  319. if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))))
  320. {
  321. $mainstmpid=(! empty($conf->global->MAIN_MAIL_SMTPS_ID)?$conf->global->MAIN_MAIL_SMTPS_ID:'');
  322. print '<tr class="drag drop oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>';
  323. // SuperAdministrator access only
  324. if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity))
  325. {
  326. print '<input class="flat" name="MAIN_MAIL_SMTPS_ID" size="32" value="' . $mainstmpid . '">';
  327. }
  328. else
  329. {
  330. $htmltext = $langs->trans("ContactSuperAdminForChange");
  331. print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_ID,$htmltext,1,'superadmin');
  332. print '<input type="hidden" name="MAIN_MAIL_SMTPS_ID" value="'.$mainstmpid.'">';
  333. }
  334. print '</td></tr>';
  335. }
  336. // PW
  337. if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))))
  338. {
  339. $mainsmtppw=(! empty($conf->global->MAIN_MAIL_SMTPS_PW)?$conf->global->MAIN_MAIL_SMTPS_PW:'');
  340. print '<tr class="drag drop oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>';
  341. // SuperAdministrator access only
  342. if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity))
  343. {
  344. print '<input class="flat" type="password" name="MAIN_MAIL_SMTPS_PW" size="32" value="' . $mainsmtppw . '">';
  345. }
  346. else
  347. {
  348. $htmltext = $langs->trans("ContactSuperAdminForChange");
  349. print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_PW,$htmltext,1,'superadmin');
  350. print '<input type="hidden" name="MAIN_MAIL_SMTPS_PW" value="'.$mainsmtppw.'">';
  351. }
  352. print '</td></tr>';
  353. }
  354. // TLS
  355. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
  356. if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))))
  357. {
  358. if (function_exists('openssl_open'))
  359. {
  360. print $form->selectyesno('MAIN_MAIL_EMAIL_TLS',(! empty($conf->global->MAIN_MAIL_EMAIL_TLS)?$conf->global->MAIN_MAIL_EMAIL_TLS:0),1);
  361. }
  362. else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  363. }
  364. else print yn(0).' ('.$langs->trans("NotSupported").')';
  365. print '</td></tr>';
  366. // STARTTLS
  367. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
  368. if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))))
  369. {
  370. if (function_exists('openssl_open'))
  371. {
  372. print $form->selectyesno('MAIN_MAIL_EMAIL_STARTTLS',(! empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS)?$conf->global->MAIN_MAIL_EMAIL_STARTTLS:0),1);
  373. }
  374. else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  375. }
  376. else print yn(0).' ('.$langs->trans("NotSupported").')';
  377. print '</td></tr>';
  378. // DKIM
  379. print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_ENABLED").'</td><td>';
  380. if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('swiftmailer'))))
  381. {
  382. if (function_exists('openssl_open'))
  383. {
  384. print $form->selectyesno('MAIN_MAIL_EMAIL_DKIM_ENABLED',(! empty($conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED)?$conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED:0),1);
  385. }
  386. else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  387. }
  388. else print yn(0).' ('.$langs->trans("NotSupported").')';
  389. print '</td></tr>';
  390. // DKIM Domain
  391. print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_DOMAIN").'</td>';
  392. print '<td><input class="flat" id="MAIN_MAIL_EMAIL_DKIM_DOMAIN" name="MAIN_MAIL_EMAIL_DKIM_DOMAIN" size="32" value="' . (! empty($conf->global->MAIN_MAIL_EMAIL_DKIM_DOMAIN)?$conf->global->MAIN_MAIL_EMAIL_DKIM_DOMAIN:'');
  393. print '"></td></tr>';
  394. // DKIM Selector
  395. print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_SELECTOR").'</td>';
  396. print '<td><input class="flat" id="MAIN_MAIL_EMAIL_DKIM_SELECTOR" name="MAIN_MAIL_EMAIL_DKIM_SELECTOR" size="32" value="' . (! empty($conf->global->MAIN_MAIL_EMAIL_DKIM_SELECTOR)?$conf->global->MAIN_MAIL_EMAIL_DKIM_SELECTOR:'');
  397. print '"></td></tr>';
  398. // DKIM PRIVATE KEY
  399. print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").'</td>';
  400. print '<td><textarea id="MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY" name="MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY" rows="15" cols="100">' . (! empty($conf->global->MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY)?$conf->global->MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY:'').'</textarea>';
  401. print '</td></tr>';
  402. // Separator
  403. print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
  404. // From
  405. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_FROM",ini_get('sendmail_from')?ini_get('sendmail_from'):$langs->transnoentities("Undefined")).'</td>';
  406. print '<td><input class="flat" name="MAIN_MAIL_EMAIL_FROM" size="32" value="' . (! empty($conf->global->MAIN_MAIL_EMAIL_FROM)?$conf->global->MAIN_MAIL_EMAIL_FROM:'');
  407. print '"></td></tr>';
  408. // Default from type
  409. $liste = array();
  410. $liste['user'] = $langs->trans('UserEmail');
  411. $liste['company'] = $langs->trans('CompanyEmail').' ('.(empty($conf->global->MAIN_INFO_SOCIETE_MAIL)?$langs->trans("NotDefined"):$conf->global->MAIN_INFO_SOCIETE_MAIL).')';
  412. /*
  413. $sql='SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile WHERE active = 1';
  414. $resql = $db->query($sql);
  415. if ($resql)
  416. {
  417. $num = $db->num_rows($resql);
  418. $i=0;
  419. while($i < $num)
  420. {
  421. $obj = $db->fetch_object($resql);
  422. if ($obj)
  423. {
  424. $liste['senderprofile_'.$obj->rowid] = $obj->label.' <'.$obj->email.'>';
  425. }
  426. $i++;
  427. }
  428. }
  429. else dol_print_error($db);*/
  430. print '<tr class="oddeven"><td>'.$langs->trans('MAIN_MAIL_DEFAULT_FROMTYPE').'</td><td>';
  431. print $form->selectarray('MAIN_MAIL_DEFAULT_FROMTYPE', $liste, $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE, 0);
  432. print '</td></tr>';
  433. // Separator
  434. print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
  435. // From
  436. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ERRORS_TO").'</td>';
  437. print '<td><input class="flat" name="MAIN_MAIL_ERRORS_TO" size="32" value="' . (! empty($conf->global->MAIN_MAIL_ERRORS_TO)?$conf->global->MAIN_MAIL_ERRORS_TO:'');
  438. print '"></td></tr>';
  439. // Autocopy to
  440. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
  441. print '<td><input class="flat" name="MAIN_MAIL_AUTOCOPY_TO" size="32" value="' . (! empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)?$conf->global->MAIN_MAIL_AUTOCOPY_TO:'');
  442. print '"></td></tr>';
  443. print '</table>';
  444. dol_fiche_end();
  445. print '<br><div class="center">';
  446. print '<input class="button" type="submit" name="save" value="'.$langs->trans("Save").'">';
  447. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  448. print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  449. print '</div>';
  450. print '</form>';
  451. }
  452. else
  453. {
  454. dol_fiche_head($head, 'common', '', -1);
  455. print $langs->trans("EMailsDesc")."<br>\n";
  456. print "<br>\n";
  457. print '<table class="noborder" width="100%">';
  458. print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  459. // Disable
  460. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_DISABLE_ALL_MAILS").'</td><td>'.yn($conf->global->MAIN_DISABLE_ALL_MAILS).'</td></tr>';
  461. // Force e-mail recipient
  462. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_FORCE_SENDTO").'</td><td>'.$conf->global->MAIN_MAIL_FORCE_SENDTO;
  463. if (! empty($conf->global->MAIN_MAIL_FORCE_SENDTO) && ! isValidEmail($conf->global->MAIN_MAIL_FORCE_SENDTO)) print img_warning($langs->trans("ErrorBadEMail"));
  464. print '</td></tr>';
  465. //Add user to select destinaries list
  466. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ENABLED_USER_DEST_SELECT").'</td><td>'.yn($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT).'</td></tr>';
  467. // Separator
  468. print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
  469. // Method
  470. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
  471. $text=$listofmethods[$conf->global->MAIN_MAIL_SENDMODE];
  472. if (empty($text)) $text=$langs->trans("Undefined").img_warning();
  473. print $text;
  474. print '</td></tr>';
  475. // Host server
  476. if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'mail'))
  477. {
  478. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike").'</td><td><span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span></td></tr>';
  479. }
  480. else
  481. {
  482. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER",ini_get('SMTP')?ini_get('SMTP'):$langs->transnoentities("Undefined")).'</td><td>'.(! empty($conf->global->MAIN_MAIL_SMTP_SERVER)?$conf->global->MAIN_MAIL_SMTP_SERVER:'').'</td></tr>';
  483. }
  484. // Port
  485. if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE) && $conf->global->MAIN_MAIL_SENDMODE == 'mail'))
  486. {
  487. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").'</td><td><span class="opacitymedium">'.$langs->trans("SeeLocalSendMailSetup").'</span></td></tr>';
  488. }
  489. else
  490. {
  491. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT",ini_get('smtp_port')?ini_get('smtp_port'):$langs->transnoentities("Undefined")).'</td><td>'.(! empty($conf->global->MAIN_MAIL_SMTP_PORT)?$conf->global->MAIN_MAIL_SMTP_PORT:'').'</td></tr>';
  492. }
  493. // SMTPS ID
  494. if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))
  495. {
  496. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>'.$conf->global->MAIN_MAIL_SMTPS_ID.'</td></tr>';
  497. }
  498. // SMTPS PW
  499. if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))
  500. {
  501. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>'.preg_replace('/./','*',$conf->global->MAIN_MAIL_SMTPS_PW).'</td></tr>';
  502. }
  503. // TLS
  504. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
  505. if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))
  506. {
  507. if (function_exists('openssl_open'))
  508. {
  509. print yn($conf->global->MAIN_MAIL_EMAIL_TLS);
  510. }
  511. else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  512. }
  513. else print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
  514. print '</td></tr>';
  515. // STARTTLS
  516. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
  517. if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))
  518. {
  519. if (function_exists('openssl_open'))
  520. {
  521. print yn($conf->global->MAIN_MAIL_EMAIL_STARTTLS);
  522. }
  523. else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  524. }
  525. else print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
  526. print '</td></tr>';
  527. if ($conf->global->MAIN_MAIL_SENDMODE == 'swiftmailer')
  528. {
  529. // DKIM
  530. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_ENABLED").'</td><td>';
  531. if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('swiftmailer')))
  532. {
  533. if (function_exists('openssl_open'))
  534. {
  535. print yn($conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED);
  536. }
  537. else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  538. }
  539. else print yn(0).' ('.$langs->trans("NotSupported").')';
  540. print '</td></tr>';
  541. // Domain
  542. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_DOMAIN").'</td>';
  543. print '<td>' . $conf->global->MAIN_MAIL_EMAIL_DKIM_DOMAIN;
  544. print '</td></tr>';
  545. // Selector
  546. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_SELECTOR").'</td>';
  547. print '<td>' . $conf->global->MAIN_MAIL_EMAIL_DKIM_SELECTOR;
  548. print '</td></tr>';
  549. // PRIVATE KEY
  550. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY").'</td>';
  551. print '<td>' . $conf->global->MAIN_MAIL_EMAIL_DKIM_PRIVATE_KEY;
  552. print '</td></tr>';
  553. }
  554. // Separator
  555. print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
  556. // From
  557. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_FROM",ini_get('sendmail_from')?ini_get('sendmail_from'):$langs->transnoentities("Undefined")).'</td>';
  558. print '<td>'.$conf->global->MAIN_MAIL_EMAIL_FROM;
  559. if (! empty($conf->global->MAIN_MAIL_EMAIL_FROM) && ! isValidEmail($conf->global->MAIN_MAIL_EMAIL_FROM)) print img_warning($langs->trans("ErrorBadEMail"));
  560. print '</td></tr>';
  561. // Default from type
  562. $liste = array();
  563. $liste['user'] = $langs->trans('UserEmail');
  564. $liste['company'] = $langs->trans('CompanyEmail').' ('.(empty($conf->global->MAIN_INFO_SOCIETE_MAIL)?$langs->trans("NotDefined"):$conf->global->MAIN_INFO_SOCIETE_MAIL).')';
  565. $sql='SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile WHERE active = 1';
  566. $resql = $db->query($sql);
  567. if ($resql)
  568. {
  569. $num = $db->num_rows($resql);
  570. $i=0;
  571. while($i < $num)
  572. {
  573. $obj = $db->fetch_object($resql);
  574. if ($obj)
  575. {
  576. $liste['senderprofile_'.$obj->rowid] = $obj->label.' <'.$obj->email.'>';
  577. }
  578. $i++;
  579. }
  580. }
  581. else dol_print_error($db);
  582. print '<tr class="oddeven"><td>'.$langs->trans('MAIN_MAIL_DEFAULT_FROMTYPE').'</td>';
  583. print '<td>';
  584. if ($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE === 'robot')
  585. {
  586. print $langs->trans('RobotEmail');
  587. }
  588. else if ($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE === 'user')
  589. {
  590. print $langs->trans('UserEmail');
  591. }
  592. else if ($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE === 'company')
  593. {
  594. print $langs->trans('CompanyEmail').' '.dol_escape_htmltag('<'.$mysoc->email.'>');
  595. }
  596. else {
  597. $id = preg_replace('/senderprofile_/', '', $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE);
  598. if ($id > 0)
  599. {
  600. include_once DOL_DOCUMENT_ROOT.'/core/class/emailsenderprofile.class.php';
  601. $emailsenderprofile = new EmailSenderProfile($db);
  602. $emailsenderprofile->fetch($id);
  603. print $emailsenderprofile->label.' '.dol_escape_htmltag('<'.$emailsenderprofile->email.'>');
  604. }
  605. }
  606. print '</td></tr>';
  607. // Separator
  608. print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
  609. // Errors To
  610. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ERRORS_TO").'</td>';
  611. print '<td>'.$conf->global->MAIN_MAIL_ERRORS_TO;
  612. if (! empty($conf->global->MAIN_MAIL_ERRORS_TO) && ! isValidEmail($conf->global->MAIN_MAIL_ERRORS_TO)) print img_warning($langs->trans("ErrorBadEMail"));
  613. print '</td></tr>';
  614. // Autocopy to
  615. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
  616. print '<td>';
  617. if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_TO))
  618. {
  619. print $conf->global->MAIN_MAIL_AUTOCOPY_TO;
  620. if (! isValidEmail($conf->global->MAIN_MAIL_AUTOCOPY_TO)) print img_warning($langs->trans("ErrorBadEMail"));
  621. }
  622. else
  623. {
  624. print '&nbsp;';
  625. }
  626. print '</td></tr>';
  627. print '</table>';
  628. dol_fiche_end();
  629. // Actions button
  630. print '<div class="tabsAction">';
  631. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
  632. if ($conf->global->MAIN_MAIL_SENDMODE != 'mail' || ! $linuxlike)
  633. {
  634. if (function_exists('fsockopen') && $port && $server)
  635. {
  636. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect#formmailbeforetitle">'.$langs->trans("DoTestServerAvailability").'</a>';
  637. }
  638. }
  639. else
  640. {
  641. print '<a class="butActionRefused" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
  642. }
  643. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&mode=init#formmailbeforetitle">'.$langs->trans("DoTestSend").'</a>';
  644. if (! empty($conf->fckeditor->enabled))
  645. {
  646. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testhtml&mode=init#formmailbeforetitle">'.$langs->trans("DoTestSendHTML").'</a>';
  647. }
  648. print '</div>';
  649. if ($conf->global->MAIN_MAIL_SENDMODE == 'mail' && empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA))
  650. {
  651. /*
  652. // Warning 1
  653. if ($linuxlike)
  654. {
  655. $sendmailoption=ini_get('mail.force_extra_parameters');
  656. if (empty($sendmailoption) || ! preg_match('/ba/',$sendmailoption))
  657. {
  658. print info_admin($langs->trans("SendmailOptionNotComplete"));
  659. }
  660. }*/
  661. // Warning 2
  662. print info_admin($langs->trans("SendmailOptionMayHurtBuggedMTA"));
  663. }
  664. if (! in_array($action, array('testconnect', 'test', 'testhtml')))
  665. {
  666. $text = '';
  667. if ($conf->global->MAIN_MAIL_SENDMODE == 'mail')
  668. {
  669. $text.= $langs->trans("WarningPHPMail");
  670. }
  671. //$conf->global->MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS='1.2.3.4';
  672. if (! empty($conf->global->MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS))
  673. {
  674. $text.= ($text?'<br>':'').$langs->trans("WarningPHPMail2", $conf->global->MAIN_EXTERNAL_SMTP_CLIENT_IP_ADDRESS);
  675. }
  676. if ($text) print info_admin($text);
  677. }
  678. // Run the test to connect
  679. if ($action == 'testconnect')
  680. {
  681. print load_fiche_titre($langs->trans("DoTestServerAvailability"));
  682. include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  683. $mail = new CMailFile('','','','');
  684. $result=$mail->check_server_port($server,$port);
  685. if ($result) print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort",$server,$port).'</div>';
  686. else
  687. {
  688. $errormsg = $langs->trans("ServerNotAvailableOnIPOrPort",$server,$port);
  689. if ($mail->error) {
  690. $errormsg .= ' - '.$mail->error;
  691. }
  692. setEventMessages($errormsg, null, 'errors');
  693. }
  694. print '<br>';
  695. }
  696. // Show email send test form
  697. if ($action == 'test' || $action == 'testhtml')
  698. {
  699. print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
  700. print load_fiche_titre($action == 'testhtml'?$langs->trans("DoTestSendHTML"):$langs->trans("DoTestSend"));
  701. dol_fiche_head('');
  702. // Cree l'objet formulaire mail
  703. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  704. $formmail = new FormMail($db);
  705. $formmail->trackid=(($action == 'testhtml')?"testhtml":"test");
  706. $formmail->fromname = (isset($_POST['fromname'])?$_POST['fromname']:$conf->global->MAIN_MAIL_EMAIL_FROM);
  707. $formmail->frommail = (isset($_POST['frommail'])?$_POST['frommail']:$conf->global->MAIN_MAIL_EMAIL_FROM);
  708. $formmail->fromid=$user->id;
  709. $formmail->fromalsorobot=1;
  710. $formmail->fromtype=(GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
  711. $formmail->withfromreadonly=1;
  712. $formmail->withsubstit=1;
  713. $formmail->withfrom=1;
  714. $formmail->witherrorsto=1;
  715. $formmail->withto=(! empty($_POST['sendto'])?$_POST['sendto']:($user->email?$user->email:1));
  716. $formmail->withtocc=(! empty($_POST['sendtocc'])?$_POST['sendtocc']:1); // ! empty to keep field if empty
  717. $formmail->withtoccc=(! empty($_POST['sendtoccc'])?$_POST['sendtoccc']:1); // ! empty to keep field if empty
  718. $formmail->withtopic=(isset($_POST['subject'])?$_POST['subject']:$langs->trans("Test"));
  719. $formmail->withtopicreadonly=0;
  720. $formmail->withfile=2;
  721. $formmail->withbody=(isset($_POST['message'])?$_POST['message']:($action == 'testhtml'?$langs->transnoentities("PredefinedMailTestHtml"):$langs->transnoentities("PredefinedMailTest")));
  722. $formmail->withbodyreadonly=0;
  723. $formmail->withcancel=1;
  724. $formmail->withdeliveryreceipt=1;
  725. $formmail->withfckeditor=($action == 'testhtml'?1:0);
  726. $formmail->ckeditortoolbar='dolibarr_mailings';
  727. // Tableau des substitutions
  728. $formmail->substit=$substitutionarrayfortest;
  729. // Tableau des parametres complementaires du post
  730. $formmail->param["action"]="send";
  731. $formmail->param["models"]="body";
  732. $formmail->param["mailid"]=0;
  733. $formmail->param["returnurl"]=$_SERVER["PHP_SELF"];
  734. // Init list of files
  735. if (GETPOST("mode")=='init')
  736. {
  737. $formmail->clear_attached_files();
  738. }
  739. print $formmail->get_form('addfile','removefile');
  740. dol_fiche_end();
  741. }
  742. }
  743. // End of page
  744. llxFooter();
  745. $db->close();