mails_emailing.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2016 Jonathan TISSEAU <jonathan.tisseau@86dev.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <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. '__LOGIN__' => $user->login,
  39. '__ID__' => 'TESTIdRecord',
  40. '__EMAIL__' => 'TESTEMail',
  41. '__LASTNAME__' => 'TESTLastname',
  42. '__FIRSTNAME__' => 'TESTFirstname',
  43. '__USER_SIGNATURE__' => (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))?$usersignature:''),
  44. //'__PERSONALIZED__' => 'TESTPersonalized' // Hiden because not used yet
  45. );
  46. complete_substitutions_array($substitutionarrayfortest, $langs);
  47. /*
  48. * Actions
  49. */
  50. if ($action == 'update' && empty($_POST["cancel"]))
  51. {
  52. // Send mode parameters
  53. dolibarr_set_const($db, "MAIN_MAIL_SENDMODE_EMAILING", GETPOST("MAIN_MAIL_SENDMODE_EMAILING"),'chaine',0,'',$conf->entity);
  54. dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT_EMAILING", GETPOST("MAIN_MAIL_SMTP_PORT_EMAILING"),'chaine',0,'',$conf->entity);
  55. dolibarr_set_const($db, "MAIN_MAIL_SMTP_SERVER_EMAILING", GETPOST("MAIN_MAIL_SMTP_SERVER_EMAILING"),'chaine',0,'',$conf->entity);
  56. dolibarr_set_const($db, "MAIN_MAIL_SMTPS_ID_EMAILING", GETPOST("MAIN_MAIL_SMTPS_ID_EMAILING"), 'chaine',0,'',$conf->entity);
  57. dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW_EMAILING", GETPOST("MAIN_MAIL_SMTPS_PW_EMAILING"), 'chaine',0,'',$conf->entity);
  58. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS_EMAILING", GETPOST("MAIN_MAIL_EMAIL_TLS_EMAILING"),'chaine',0,'',$conf->entity);
  59. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS_EMAILING", GETPOST("MAIN_MAIL_EMAIL_STARTTLS_EMAILING"),'chaine',0,'',$conf->entity);
  60. header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
  61. exit;
  62. }
  63. // Actions to send emails
  64. $id=0;
  65. $actiontypecode=''; // Not an event for agenda
  66. $trigger_name=''; // Disable triggers
  67. $paramname='id';
  68. $mode='emailfortest';
  69. $trackid=(($action == 'testhtml')?"testhtml":"test");
  70. $sendcontext='emailing'; // Force to use dedicated context of setup for emailing
  71. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  72. if ($action == 'presend' && GETPOST('trackid') == 'test') $action='test';
  73. if ($action == 'presend' && GETPOST('trackid') == 'testhtml') $action='testhtml';
  74. /*
  75. * View
  76. */
  77. $linuxlike=1;
  78. if (preg_match('/^win/i',PHP_OS)) $linuxlike=0;
  79. if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0;
  80. if (empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING)) $conf->global->MAIN_MAIL_SENDMODE_EMAILING='default';
  81. $port=! empty($conf->global->MAIN_MAIL_SMTP_PORT_EMAILING)?$conf->global->MAIN_MAIL_SMTP_PORT_EMAILING:ini_get('smtp_port');
  82. if (! $port) $port=25;
  83. $server=! empty($conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING)?$conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING:ini_get('SMTP');
  84. if (! $server) $server='127.0.0.1';
  85. $wikihelp='EN:Setup_EMails|FR:Paramétrage_EMails|ES:Configuración_EMails';
  86. llxHeader('',$langs->trans("Setup"),$wikihelp);
  87. print load_fiche_titre($langs->trans("EMailsSetup"),'','title_setup');
  88. $head = email_admin_prepare_head();
  89. // List of sending methods
  90. $listofmethods=array();
  91. $listofmethods['default']=$langs->trans('DefaultOutgoingEmailSetup');
  92. $listofmethods['mail']='PHP mail function';
  93. //$listofmethods['simplemail']='Simplemail class';
  94. $listofmethods['smtps']='SMTP/SMTPS socket library';
  95. $listofmethods['swiftmailer']='Swift Mailer socket library';
  96. if ($action == 'edit')
  97. {
  98. $form=new Form($db);
  99. if ($conf->use_javascript_ajax)
  100. {
  101. print "\n".'<script type="text/javascript" language="javascript">';
  102. print 'jQuery(document).ready(function () {
  103. function initfields()
  104. {
  105. if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'default\')
  106. {
  107. jQuery(".hideifdefault").hide();
  108. }
  109. else
  110. {
  111. jQuery(".hideifdefault").show();
  112. }
  113. if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'mail\')
  114. {
  115. jQuery(".drag").hide();
  116. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val(0);
  117. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").prop("disabled", true);
  118. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val(0);
  119. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").prop("disabled", true);
  120. ';
  121. if ($linuxlike)
  122. {
  123. print '
  124. jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").hide();
  125. jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").hide();
  126. jQuery("#smtp_server_mess").show();
  127. jQuery("#smtp_port_mess").show();
  128. ';
  129. }
  130. else
  131. {
  132. print '
  133. jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").prop("disabled", true);
  134. jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").prop("disabled", true);
  135. jQuery("#smtp_server_mess").hide();
  136. jQuery("#smtp_port_mess").hide();
  137. ';
  138. }
  139. print '
  140. }
  141. if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'smtps\')
  142. {
  143. jQuery(".drag").show();
  144. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING.');
  145. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").removeAttr("disabled");
  146. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING.');
  147. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").removeAttr("disabled");
  148. jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").removeAttr("disabled");
  149. jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").removeAttr("disabled");
  150. jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").show();
  151. jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").show();
  152. jQuery("#smtp_server_mess").hide();
  153. jQuery("#smtp_port_mess").hide();
  154. }
  155. if (jQuery("#MAIN_MAIL_SENDMODE_EMAILING").val()==\'swiftmailer\')
  156. {
  157. jQuery(".drag").show();
  158. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING.');
  159. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").removeAttr("disabled");
  160. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING.');
  161. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").removeAttr("disabled");
  162. jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").removeAttr("disabled");
  163. jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").removeAttr("disabled");
  164. jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").show();
  165. jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").show();
  166. jQuery("#smtp_server_mess").hide();
  167. jQuery("#smtp_port_mess").hide();
  168. }
  169. }
  170. initfields();
  171. jQuery("#MAIN_MAIL_SENDMODE_EMAILING").change(function() {
  172. initfields();
  173. });
  174. jQuery("#MAIN_MAIL_EMAIL_TLS").change(function() {
  175. if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val() == 1)
  176. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val(0);
  177. });
  178. jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").change(function() {
  179. if (jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val() == 1)
  180. jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val(0);
  181. });
  182. })';
  183. print '</script>'."\n";
  184. }
  185. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  186. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  187. print '<input type="hidden" name="action" value="update">';
  188. dol_fiche_head($head, 'common_emailing', '', -1);
  189. print $langs->trans("EMailsDesc")."<br>\n";
  190. print "<br>\n";
  191. clearstatcache();
  192. print '<table class="noborder" width="100%">';
  193. print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  194. // Method
  195. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
  196. // SuperAdministrator access only
  197. if ((empty($conf->global->MAIN_MODULE_MULTICOMPANY)) || ($user->admin && !$user->entity))
  198. {
  199. print $form->selectarray('MAIN_MAIL_SENDMODE_EMAILING',$listofmethods,$conf->global->MAIN_MAIL_SENDMODE_EMAILING);
  200. }
  201. else
  202. {
  203. $text = $listofmethods[$conf->global->MAIN_MAIL_SENDMODE_EMAILING];
  204. if (empty($text)) $text = $langs->trans("Undefined");
  205. $htmltext = $langs->trans("ContactSuperAdminForChange");
  206. print $form->textwithpicto($text,$htmltext,1,'superadmin');
  207. print '<input type="hidden" name="MAIN_MAIL_SENDMODE_EMAILING" value="'.$conf->global->MAIN_MAIL_SENDMODE_EMAILING.'">';
  208. }
  209. print '</td></tr>';
  210. // Host server
  211. print '<tr class="oddeven hideifdefault"><td>';
  212. if (! $conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail')
  213. {
  214. print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
  215. print '</td><td>';
  216. print $langs->trans("SeeLocalSendMailSetup");
  217. }
  218. else
  219. {
  220. $mainserver = (! empty($conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING)?$conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING:'');
  221. $smtpserver = ini_get('SMTP')?ini_get('SMTP'):$langs->transnoentities("Undefined");
  222. if ($linuxlike) print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
  223. else print $langs->trans("MAIN_MAIL_SMTP_SERVER",$smtpserver);
  224. print '</td><td>';
  225. // SuperAdministrator access only
  226. if (empty($conf->multicompany->enabled) || ($user->admin && ! $user->entity))
  227. {
  228. print '<input class="flat" id="MAIN_MAIL_SMTP_SERVER_EMAILING" name="MAIN_MAIL_SMTP_SERVER_EMAILING" size="18" value="' . $mainserver . '">';
  229. print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_EMAILING_sav" name="MAIN_MAIL_SMTP_SERVER_EMAILING_sav" value="' . $mainserver . '">';
  230. print '<span id="smtp_server_mess">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
  231. }
  232. else
  233. {
  234. $text = ! empty($mainserver) ? $mainserver : $smtpserver;
  235. $htmltext = $langs->trans("ContactSuperAdminForChange");
  236. print $form->textwithpicto($text,$htmltext,1,'superadmin');
  237. print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER_EMAILING" name="MAIN_MAIL_SMTP_SERVER_EMAILING" value="'.$mainserver.'">';
  238. }
  239. }
  240. print '</td></tr>';
  241. // Port
  242. print '<tr class="oddeven hideifdefault"><td>';
  243. if (! $conf->use_javascript_ajax && $linuxlike && $conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail')
  244. {
  245. print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
  246. print '</td><td>';
  247. print $langs->trans("SeeLocalSendMailSetup");
  248. }
  249. else
  250. {
  251. $mainport = (! empty($conf->global->MAIN_MAIL_SMTP_PORT_EMAILING) ? $conf->global->MAIN_MAIL_SMTP_PORT_EMAILING : '');
  252. $smtpport = ini_get('smtp_port')?ini_get('smtp_port'):$langs->transnoentities("Undefined");
  253. if ($linuxlike) print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
  254. else print $langs->trans("MAIN_MAIL_SMTP_PORT",$smtpport);
  255. print '</td><td>';
  256. // SuperAdministrator access only
  257. if (empty($conf->multicompany->enabled) || ($user->admin && ! $user->entity))
  258. {
  259. print '<input class="flat" id="MAIN_MAIL_SMTP_PORT_EMAILING" name="MAIN_MAIL_SMTP_PORT_EMAILING" size="3" value="' . $mainport . '">';
  260. print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_EMAILING_sav" name="MAIN_MAIL_SMTP_PORT_EMAILING_sav" value="' . $mainport . '">';
  261. print '<span id="smtp_port_mess">'.$langs->trans("SeeLocalSendMailSetup").'</span>';
  262. }
  263. else
  264. {
  265. $text = (! empty($mainport) ? $mainport : $smtpport);
  266. $htmltext = $langs->trans("ContactSuperAdminForChange");
  267. print $form->textwithpicto($text,$htmltext,1,'superadmin');
  268. print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT_EMAILING" name="MAIN_MAIL_SMTP_PORT_EMAILING" value="'.$mainport.'">';
  269. }
  270. }
  271. print '</td></tr>';
  272. // ID
  273. if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))))
  274. {
  275. $mainstmpid=(! empty($conf->global->MAIN_MAIL_SMTPS_ID_EMAILING)?$conf->global->MAIN_MAIL_SMTPS_ID_EMAILING:'');
  276. print '<tr class="drag drop oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>';
  277. // SuperAdministrator access only
  278. if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity))
  279. {
  280. print '<input class="flat" name="MAIN_MAIL_SMTPS_ID_EMAILING" size="32" value="' . $mainstmpid . '">';
  281. }
  282. else
  283. {
  284. $htmltext = $langs->trans("ContactSuperAdminForChange");
  285. print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_ID_EMAILING,$htmltext,1,'superadmin');
  286. print '<input type="hidden" name="MAIN_MAIL_SMTPS_ID_EMAILING" value="'.$mainstmpid.'">';
  287. }
  288. print '</td></tr>';
  289. }
  290. // PW
  291. if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))))
  292. {
  293. $mainsmtppw=(! empty($conf->global->MAIN_MAIL_SMTPS_PW_EMAILING)?$conf->global->MAIN_MAIL_SMTPS_PW_EMAILING:'');
  294. print '<tr class="drag drop oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>';
  295. // SuperAdministrator access only
  296. if (empty($conf->multicompany->enabled) || ($user->admin && !$user->entity))
  297. {
  298. print '<input class="flat" type="password" name="MAIN_MAIL_SMTPS_PW_EMAILING" size="32" value="' . $mainsmtppw . '">';
  299. }
  300. else
  301. {
  302. $htmltext = $langs->trans("ContactSuperAdminForChange");
  303. print $form->textwithpicto($conf->global->MAIN_MAIL_SMTPS_PW_EMAILING,$htmltext,1,'superadmin');
  304. print '<input type="hidden" name="MAIN_MAIL_SMTPS_PW_EMAILING" value="'.$mainsmtppw.'">';
  305. }
  306. print '</td></tr>';
  307. }
  308. // TLS
  309. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
  310. if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))))
  311. {
  312. if (function_exists('openssl_open'))
  313. {
  314. print $form->selectyesno('MAIN_MAIL_EMAIL_TLS_EMAILING',(! empty($conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING)?$conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING:0),1);
  315. }
  316. else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  317. }
  318. else print yn(0).' ('.$langs->trans("NotSupported").')';
  319. print '</td></tr>';
  320. // STARTTLS
  321. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
  322. if (! empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))))
  323. {
  324. if (function_exists('openssl_open'))
  325. {
  326. print $form->selectyesno('MAIN_MAIL_EMAIL_STARTTLS_EMAILING',(! empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING)?$conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING:0),1);
  327. }
  328. else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  329. }
  330. else print yn(0).' ('.$langs->trans("NotSupported").')';
  331. print '</td></tr>';
  332. print '</table>';
  333. dol_fiche_end();
  334. print '<br><div class="center">';
  335. print '<input class="button" type="submit" name="save" value="'.$langs->trans("Save").'">';
  336. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  337. print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  338. print '</div>';
  339. print '</form>';
  340. }
  341. else
  342. {
  343. dol_fiche_head($head, 'common_emailing', '', -1);
  344. print $langs->trans("EMailsDesc")."<br>\n";
  345. print "<br>\n";
  346. print '<table class="noborder" width="100%">';
  347. print '<tr class="liste_titre"><td class="titlefieldmiddle">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  348. // Method
  349. print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
  350. $text=$listofmethods[$conf->global->MAIN_MAIL_SENDMODE_EMAILING];
  351. if (empty($text)) $text=$langs->trans("Undefined").img_warning();
  352. print $text;
  353. print '</td></tr>';
  354. if (! empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default')
  355. {
  356. // Host server
  357. if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail'))
  358. {
  359. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
  360. }
  361. else
  362. {
  363. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER",ini_get('SMTP')?ini_get('SMTP'):$langs->transnoentities("Undefined")).'</td><td>'.(! empty($conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING)?$conf->global->MAIN_MAIL_SMTP_SERVER_EMAILING:'').'</td></tr>';
  364. }
  365. // Port
  366. if ($linuxlike && (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail'))
  367. {
  368. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
  369. }
  370. else
  371. {
  372. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT",ini_get('smtp_port')?ini_get('smtp_port'):$langs->transnoentities("Undefined")).'</td><td>'.(! empty($conf->global->MAIN_MAIL_SMTP_PORT_EMAILING)?$conf->global->MAIN_MAIL_SMTP_PORT_EMAILING:'').'</td></tr>';
  373. }
  374. // SMTPS ID
  375. if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))
  376. {
  377. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>'.$conf->global->MAIN_MAIL_SMTPS_ID_EMAILING.'</td></tr>';
  378. }
  379. // SMTPS PW
  380. if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))
  381. {
  382. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>'.preg_replace('/./','*',$conf->global->MAIN_MAIL_SMTPS_PW_EMAILING).'</td></tr>';
  383. }
  384. // TLS
  385. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
  386. if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))
  387. {
  388. if (function_exists('openssl_open'))
  389. {
  390. print yn($conf->global->MAIN_MAIL_EMAIL_TLS_EMAILING);
  391. }
  392. else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  393. }
  394. else print yn(0).' ('.$langs->trans("NotSupported").')';
  395. print '</td></tr>';
  396. // STARTTLS
  397. print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_STARTTLS").'</td><td>';
  398. if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))
  399. {
  400. if (function_exists('openssl_open'))
  401. {
  402. print yn($conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING);
  403. }
  404. else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  405. }
  406. else print yn(0).' ('.$langs->trans("NotSupported").')';
  407. print '</td></tr>';
  408. }
  409. print '</table>';
  410. dol_fiche_end();
  411. if ($conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail' && empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA))
  412. {
  413. print '<br>';
  414. /*
  415. // Warning 1
  416. if ($linuxlike)
  417. {
  418. $sendmailoption=ini_get('mail.force_extra_parameters');
  419. if (empty($sendmailoption) || ! preg_match('/ba/',$sendmailoption))
  420. {
  421. print info_admin($langs->trans("SendmailOptionNotComplete"));
  422. }
  423. }*/
  424. // Warning 2
  425. print info_admin($langs->trans("SendmailOptionMayHurtBuggedMTA"));
  426. }
  427. // Boutons actions
  428. print '<div class="tabsAction">';
  429. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
  430. if (! empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default')
  431. {
  432. if ($conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'mail' || ! $linuxlike)
  433. {
  434. if (function_exists('fsockopen') && $port && $server)
  435. {
  436. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
  437. }
  438. }
  439. else
  440. {
  441. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
  442. }
  443. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&amp;mode=init">'.$langs->trans("DoTestSend").'</a>';
  444. if (! empty($conf->fckeditor->enabled))
  445. {
  446. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testhtml&amp;mode=init">'.$langs->trans("DoTestSendHTML").'</a>';
  447. }
  448. }
  449. print '</div>';
  450. if ($conf->global->MAIN_MAIL_SENDMODE_EMAILING == 'mail' && ! in_array($action, array('testconnect', 'test', 'testhtml')))
  451. {
  452. $text = $langs->trans("WarningPHPMail");
  453. print info_admin($text);
  454. }
  455. // Run the test to connect
  456. if ($action == 'testconnect')
  457. {
  458. print load_fiche_titre($langs->trans("DoTestServerAvailability"));
  459. include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  460. $mail = new CMailFile('','','','');
  461. $result=$mail->check_server_port($server,$port);
  462. if ($result) print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort",$server,$port).'</div>';
  463. else
  464. {
  465. $errormsg = $langs->trans("ServerNotAvailableOnIPOrPort",$server,$port);
  466. if ($mail->error) {
  467. $errormsg .= ' - '.$mail->error;
  468. }
  469. setEventMessages($errormsg, null, 'errors');
  470. }
  471. print '<br>';
  472. }
  473. // Show email send test form
  474. if ($action == 'test' || $action == 'testhtml')
  475. {
  476. print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
  477. print load_fiche_titre($action == 'testhtml'?$langs->trans("DoTestSendHTML"):$langs->trans("DoTestSend"));
  478. dol_fiche_head('');
  479. // Cree l'objet formulaire mail
  480. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  481. $formmail = new FormMail($db);
  482. $formmail->fromname = (isset($_POST['fromname'])?$_POST['fromname']:$conf->global->MAIN_MAIL_EMAIL_FROM);
  483. $formmail->frommail = (isset($_POST['frommail'])?$_POST['frommail']:$conf->global->MAIN_MAIL_EMAIL_FROM);
  484. $formmail->trackid=(($action == 'testhtml')?"testhtml":"test");
  485. $formmail->withfromreadonly=0;
  486. $formmail->withsubstit=0;
  487. $formmail->withfrom=1;
  488. $formmail->witherrorsto=1;
  489. $formmail->withto=(! empty($_POST['sendto'])?$_POST['sendto']:($user->email?$user->email:1));
  490. $formmail->withtocc=(! empty($_POST['sendtocc'])?$_POST['sendtocc']:1); // ! empty to keep field if empty
  491. $formmail->withtoccc=(! empty($_POST['sendtoccc'])?$_POST['sendtoccc']:1); // ! empty to keep field if empty
  492. $formmail->withtopic=(isset($_POST['subject'])?$_POST['subject']:$langs->trans("Test"));
  493. $formmail->withtopicreadonly=0;
  494. $formmail->withfile=2;
  495. $formmail->withbody=(isset($_POST['message'])?$_POST['message']:($action == 'testhtml'?$langs->transnoentities("PredefinedMailTestHtml"):$langs->transnoentities("PredefinedMailTest")));
  496. $formmail->withbodyreadonly=0;
  497. $formmail->withcancel=1;
  498. $formmail->withdeliveryreceipt=1;
  499. $formmail->withfckeditor=($action == 'testhtml'?1:0);
  500. $formmail->ckeditortoolbar='dolibarr_mailings';
  501. // Tableau des substitutions
  502. $formmail->substit=$substitutionarrayfortest;
  503. // Tableau des parametres complementaires du post
  504. $formmail->param["action"]="send";
  505. $formmail->param["models"]="body";
  506. $formmail->param["mailid"]=0;
  507. $formmail->param["returnurl"]=$_SERVER["PHP_SELF"];
  508. // Init list of files
  509. if (GETPOST("mode")=='init')
  510. {
  511. $formmail->clear_attached_files();
  512. }
  513. print $formmail->get_form('addfile','removefile');
  514. dol_fiche_end();
  515. }
  516. }
  517. // End of page
  518. llxFooter();
  519. $db->close();