mails.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. <?php
  2. /* Copyright (C) 2007-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2009-2011 Regis Houssin <regis@dolibarr.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/admin/mails.php
  20. * \brief Page to setup emails sending
  21. */
  22. require("../main.inc.php");
  23. require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
  24. require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
  25. $langs->load("companies");
  26. $langs->load("products");
  27. $langs->load("admin");
  28. $langs->load("mails");
  29. $langs->load("other");
  30. $langs->load("errors");
  31. if (!$user->admin)
  32. accessforbidden();
  33. $substitutionarrayfortest=array(
  34. '__LOGIN__' => $user->login,
  35. '__ID__' => 'TESTIdRecord',
  36. '__EMAIL__' => 'TESTEMail',
  37. '__LASTNAME__' => 'TESTLastname',
  38. '__FIRSTNAME__' => 'TESTFirstname'
  39. );
  40. complete_substitutions_array($substitutionarrayfortest, $langs);
  41. /*
  42. * Actions
  43. */
  44. if (isset($_POST["action"]) && $_POST["action"] == 'update' && empty($_POST["cancel"]))
  45. {
  46. dolibarr_set_const($db, "MAIN_DISABLE_ALL_MAILS", $_POST["MAIN_DISABLE_ALL_MAILS"],'chaine',0,'',$conf->entity);
  47. dolibarr_set_const($db, "MAIN_MAIL_SENDMODE", $_POST["MAIN_MAIL_SENDMODE"],'chaine',0,'',0);
  48. dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT", $_POST["MAIN_MAIL_SMTP_PORT"],'chaine',0,'',0);
  49. dolibarr_set_const($db, "MAIN_MAIL_SMTP_SERVER", $_POST["MAIN_MAIL_SMTP_SERVER"],'chaine',0,'',0);
  50. if (isset($_POST["MAIN_MAIL_SMTPS_ID"])) dolibarr_set_const($db, "MAIN_MAIL_SMTPS_ID", $_POST["MAIN_MAIL_SMTPS_ID"],'chaine',0,'',0);
  51. if (isset($_POST["MAIN_MAIL_SMTPS_PW"])) dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW", $_POST["MAIN_MAIL_SMTPS_PW"],'chaine',0,'',0);
  52. if (isset($_POST["MAIN_MAIL_EMAIL_TLS"])) dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS", $_POST["MAIN_MAIL_EMAIL_TLS"],'chaine',0,'',0);
  53. dolibarr_set_const($db, "MAIN_MAIL_EMAIL_FROM", $_POST["MAIN_MAIL_EMAIL_FROM"],'chaine',0,'',$conf->entity);
  54. dolibarr_set_const($db, "MAIN_MAIL_ERRORS_TO", $_POST["MAIN_MAIL_ERRORS_TO"],'chaine',0,'',$conf->entity);
  55. dolibarr_set_const($db, "MAIN_MAIL_AUTOCOPY_TO", $_POST["MAIN_MAIL_AUTOCOPY_TO"],'chaine',0,'',$conf->entity);
  56. Header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
  57. exit;
  58. }
  59. /*
  60. * Add file in email form
  61. */
  62. if ($_POST['addfile'] || $_POST['addfilehtml'])
  63. {
  64. require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
  65. // Set tmp user directory
  66. $vardir=$conf->user->dir_output."/".$user->id;
  67. $upload_dir = $vardir.'/temp';
  68. if (create_exdir($upload_dir) >= 0)
  69. {
  70. $resupload=dol_move_uploaded_file($_FILES['addedfile']['tmp_name'], $upload_dir . "/" . $_FILES['addedfile']['name'],0,0,$_FILES['addedfile']['error']);
  71. if (is_numeric($resupload) && $resupload > 0)
  72. {
  73. $mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
  74. include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
  75. $formmail = new FormMail($db);
  76. $formmail->add_attached_files($upload_dir . "/" . $_FILES['addedfile']['name'],$_FILES['addedfile']['name'],$_FILES['addedfile']['type']);
  77. }
  78. else
  79. {
  80. $langs->load("errors");
  81. if ($resupload < 0) // Unknown error
  82. {
  83. $mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
  84. }
  85. else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
  86. {
  87. $mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
  88. }
  89. else // Known error
  90. {
  91. $mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
  92. }
  93. }
  94. }
  95. else
  96. {
  97. $langs->load("errors");
  98. $mesg = '<div class="error">'.$langs->trans("ErrorFailToCreateDir",$upload_dir).'</div>';
  99. }
  100. if ($_POST['addfile']) $_GET["action"]='test';
  101. if ($_POST['addfilehtml']) $_GET["action"]='testhtml';
  102. }
  103. /*
  104. * Remove file in email form
  105. */
  106. if (! empty($_POST['removedfile']) || ! empty($_POST['removedfilehtml']))
  107. {
  108. // Set tmp user directory
  109. $vardir=$conf->user->dir_output."/".$user->id;
  110. $upload_dir = $vardir.'/temp';
  111. $keytodelete=isset($_POST['removedfile'])?$_POST['removedfile']:$_POST['removedfilehtml'];
  112. $keytodelete--;
  113. $listofpaths=array();
  114. $listofnames=array();
  115. $listofmimes=array();
  116. if (! empty($_SESSION["listofpaths"])) $listofpaths=explode(';',$_SESSION["listofpaths"]);
  117. if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]);
  118. if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]);
  119. if ($keytodelete >= 0)
  120. {
  121. $pathtodelete=$listofpaths[$keytodelete];
  122. $filetodelete=$listofnames[$keytodelete];
  123. $result = dol_delete_file($pathtodelete,1);
  124. if ($result >= 0)
  125. {
  126. $message = '<div class="ok">'.$langs->trans("FileWasRemoved",$filetodelete).'</div>';
  127. //print_r($_FILES);
  128. include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
  129. $formmail = new FormMail($db);
  130. $formmail->remove_attached_files($keytodelete);
  131. }
  132. }
  133. if ($_POST['removedfile']) $_GET["action"]='test';
  134. if ($_POST['removedfilehtml']) $_GET["action"]='testhtml';
  135. }
  136. /*
  137. * Send mail
  138. */
  139. if (($_POST['action'] == 'send' || $_POST['action'] == 'sendhtml')
  140. && ! $_POST['addfile'] && ! $_POST['addfilehtml'] && ! $_POST["removedfile"] && ! $_POST['cancel'])
  141. {
  142. $error=0;
  143. $email_from='';
  144. if (! empty($_POST["fromname"])) $email_from=$_POST["fromname"].' ';
  145. if (! empty($_POST["frommail"])) $email_from.='<'.$_POST["frommail"].'>';
  146. $errors_to = $_POST["errorstomail"];
  147. $sendto = $_POST["sendto"];
  148. $sendtocc = $_POST["sendtocc"];
  149. $sendtoccc = $_POST["sendtoccc"];
  150. $subject = $_POST['subject'];
  151. $body = $_POST['message'];
  152. $deliveryreceipt= $_POST["deliveryreceipt"];
  153. // Create form object
  154. include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
  155. $formmail = new FormMail($db);
  156. $attachedfiles=$formmail->get_attached_files();
  157. $filepath = $attachedfiles['paths'];
  158. $filename = $attachedfiles['names'];
  159. $mimetype = $attachedfiles['mimes'];
  160. if (empty($_POST["frommail"]))
  161. {
  162. $message='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("MailFrom")).'</div>';
  163. $_GET["action"]='test';
  164. $error++;
  165. }
  166. if (empty($sendto))
  167. {
  168. $message='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTo")).'</div>';
  169. $_GET["action"]='test';
  170. $error++;
  171. }
  172. if (! $error)
  173. {
  174. // Le message est-il en html
  175. $msgishtml=0; // Message is not HTML
  176. if ($_POST['action'] == 'sendhtml') $msgishtml=1; // Force message to HTML
  177. // Pratique les substitutions sur le sujet et message
  178. $subject=make_substitutions($subject,$substitutionarrayfortest);
  179. $body=make_substitutions($body,$substitutionarrayfortest);
  180. require_once(DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
  181. $mailfile = new CMailFile($subject,$sendto,$email_from,$body,
  182. $filepath,$mimetype,$filename,
  183. $sendtocc, $sendtoccc, $deliveryreceipt, $msgishtml,$errors_to);
  184. $result=$mailfile->sendfile();
  185. if ($result)
  186. {
  187. $message='<div class="ok">'.$langs->trans("MailSuccessfulySent",$mailfile->getValidAddress($email_from,2),$mailfile->getValidAddress($sendto,2)).'</div>';
  188. }
  189. else
  190. {
  191. $message='<div class="error">'.$langs->trans("ResultKo").'<br>'.$mailfile->error.' '.$result.'</div>';
  192. }
  193. $_GET["action"]='';
  194. }
  195. }
  196. /*
  197. * View
  198. */
  199. $linuxlike=1;
  200. if (preg_match('/^win/i',PHP_OS)) $linuxlike=0;
  201. if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0;
  202. if (empty($conf->global->MAIN_MAIL_SENDMODE)) $conf->global->MAIN_MAIL_SENDMODE='mail';
  203. $port=! empty($conf->global->MAIN_MAIL_SMTP_PORT)?$conf->global->MAIN_MAIL_SMTP_PORT:ini_get('smtp_port');
  204. if (! $port) $port=25;
  205. $server=! empty($conf->global->MAIN_MAIL_SMTP_SERVER)?$conf->global->MAIN_MAIL_SMTP_SERVER:ini_get('SMTP');
  206. if (! $server) $server='127.0.0.1';
  207. /*
  208. * View
  209. */
  210. $wikihelp='EN:Setup EMails|FR:Paramétrage EMails|ES:Configuración EMails';
  211. llxHeader('',$langs->trans("Setup"),$wikihelp);
  212. print_fiche_titre($langs->trans("EMailsSetup"),'','setup');
  213. print $langs->trans("EMailsDesc")."<br>\n";
  214. print "<br>\n";
  215. if ($message) print $message.'<br>';
  216. // List of sending methods
  217. $listofmethods=array();
  218. $listofmethods['mail']='PHP mail function';
  219. //$listofmethods['simplemail']='Simplemail class';
  220. $listofmethods['smtps']='SMTP/SMTPS socket library';
  221. if (isset($_GET["action"]) && $_GET["action"] == 'edit')
  222. {
  223. $html=new Form($db);
  224. if ($conf->use_javascript_ajax)
  225. {
  226. print "\n".'<script type="text/javascript" language="javascript">';
  227. print 'jQuery(document).ready(function () {
  228. function initfields()
  229. {
  230. if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'mail\')
  231. {
  232. jQuery(".drag").hide();
  233. jQuery("#MAIN_MAIL_EMAIL_TLS").val(0);
  234. jQuery("#MAIN_MAIL_EMAIL_TLS").attr(\'disabled\', \'disabled\');
  235. ';
  236. if ($linuxlike)
  237. {
  238. print ' jQuery("#MAIN_MAIL_SMTP_SERVER").attr(\'disabled\', \'disabled\');';
  239. print ' jQuery("#MAIN_MAIL_SMTP_PORT").attr(\'disabled\', \'disabled\');';
  240. }
  241. print '
  242. }
  243. if (jQuery("#MAIN_MAIL_SENDMODE").val()==\'smtps\')
  244. {
  245. jQuery(".drag").show();
  246. jQuery("#MAIN_MAIL_EMAIL_TLS").val('.$conf->global->MAIN_MAIL_EMAIL_TLS.');
  247. jQuery("#MAIN_MAIL_EMAIL_TLS").removeAttr(\'disabled\');
  248. jQuery("#MAIN_MAIL_SMTP_SERVER").removeAttr(\'disabled\');
  249. jQuery("#MAIN_MAIL_SMTP_PORT").removeAttr(\'disabled\');
  250. }
  251. }
  252. initfields();
  253. jQuery("#MAIN_MAIL_SENDMODE").change(function() {
  254. initfields();
  255. });
  256. })';
  257. print '</script>'."\n";
  258. }
  259. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  260. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  261. print '<input type="hidden" name="action" value="update">';
  262. clearstatcache();
  263. $var=true;
  264. print '<table class="noborder" width="100%">';
  265. print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  266. // Disable
  267. $var=!$var;
  268. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_DISABLE_ALL_MAILS").'</td><td>';
  269. print $html->selectyesno('MAIN_DISABLE_ALL_MAILS',$conf->global->MAIN_DISABLE_ALL_MAILS,1);
  270. print '</td></tr>';
  271. // Separator
  272. $var=!$var;
  273. print '<tr '.$bc[$var].'><td colspan="2">&nbsp;</td></tr>';
  274. // Method
  275. $var=!$var;
  276. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
  277. // SuperAdministrator access only
  278. if ((empty($conf->global->MAIN_MODULE_MULTICOMPANY)) || ($user->admin && !$user->entity))
  279. {
  280. print $html->selectarray('MAIN_MAIL_SENDMODE',$listofmethods,$conf->global->MAIN_MAIL_SENDMODE);
  281. }
  282. else
  283. {
  284. $text = $listofmethods[$conf->global->MAIN_MAIL_SENDMODE];
  285. if (empty($text)) $text = $langs->trans("Undefined");
  286. $htmltext = $langs->trans("ContactSuperAdminForChange");
  287. print $html->textwithpicto($text,$htmltext,1,'superadmin');
  288. print '<input type="hidden" name="MAIN_MAIL_SENDMODE" value="'.$conf->global->MAIN_MAIL_SENDMODE.'">';
  289. }
  290. print '</td></tr>';
  291. // Server
  292. $var=!$var;
  293. print '<tr '.$bc[$var].'><td>';
  294. if (! $conf->use_javascript_ajax && $linuxlike && ($conf->global->MAIN_MAIL_SENDMODE == 'mail' || $conf->global->MAIN_MAIL_SENDMODE == 'simplemail'))
  295. {
  296. print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
  297. print '</td><td>';
  298. print $langs->trans("SeeLocalSendMailSetup");
  299. }
  300. else
  301. {
  302. $smtpserver = ini_get('SMTP')?ini_get('SMTP'):$langs->transnoentities("Undefined");
  303. if ($linuxlike) print $langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike");
  304. else print $langs->trans("MAIN_MAIL_SMTP_SERVER",$smtpserver);
  305. print '</td><td>';
  306. // SuperAdministrator access only
  307. if ((empty($conf->global->MAIN_MODULE_MULTICOMPANY)) || ($user->admin && !$user->entity))
  308. {
  309. print '<input class="flat" id="MAIN_MAIL_SMTP_SERVER" name="MAIN_MAIL_SMTP_SERVER" size="18" value="' . $conf->global->MAIN_MAIL_SMTP_SERVER . '">';
  310. }
  311. else
  312. {
  313. $text = $conf->global->MAIN_MAIL_SMTP_SERVER ? $conf->global->MAIN_MAIL_SMTP_SERVER : $smtpserver;
  314. $htmltext = $langs->trans("ContactSuperAdminForChange");
  315. print $html->textwithpicto($text,$htmltext,1,'superadmin');
  316. print '<input type="hidden" id="MAIN_MAIL_SMTP_SERVER" name="MAIN_MAIL_SMTP_SERVER" value="'.$conf->global->MAIN_MAIL_SMTP_SERVER.'">';
  317. }
  318. }
  319. print '</td></tr>';
  320. // Port
  321. $var=!$var;
  322. print '<tr '.$bc[$var].'><td>';
  323. if (! $conf->use_javascript_ajax && $linuxlike && ($conf->global->MAIN_MAIL_SENDMODE == 'mail' || $conf->global->MAIN_MAIL_SENDMODE == 'simplemail'))
  324. {
  325. print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
  326. print '</td><td>';
  327. print $langs->trans("SeeLocalSendMailSetup");
  328. }
  329. else
  330. {
  331. $smtpport = ini_get('smtp_port')?ini_get('smtp_port'):$langs->transnoentities("Undefined");
  332. if ($linuxlike) print $langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike");
  333. else print $langs->trans("MAIN_MAIL_SMTP_PORT",$smtpport);
  334. print '</td><td>';
  335. // SuperAdministrator access only
  336. if ((empty($conf->global->MAIN_MODULE_MULTICOMPANY)) || ($user->admin && !$user->entity))
  337. {
  338. print '<input class="flat" id="MAIN_MAIL_SMTP_PORT" name="MAIN_MAIL_SMTP_PORT" size="3" value="' . $conf->global->MAIN_MAIL_SMTP_PORT . '">';
  339. }
  340. else
  341. {
  342. $text = $conf->global->MAIN_MAIL_SMTP_PORT ? $conf->global->MAIN_MAIL_SMTP_PORT : $smtpport;
  343. $htmltext = $langs->trans("ContactSuperAdminForChange");
  344. print $html->textwithpicto($text,$htmltext,1,'superadmin');
  345. print '<input type="hidden" id="MAIN_MAIL_SMTP_PORT" name="MAIN_MAIL_SMTP_PORT" value="'.$conf->global->MAIN_MAIL_SMTP_PORT.'">';
  346. }
  347. }
  348. print '</td></tr>';
  349. // ID
  350. if ($conf->use_javascript_ajax || $conf->global->MAIN_MAIL_SENDMODE == 'smtps')
  351. {
  352. $var=!$var;
  353. print '<tr '.$bcdd[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>';
  354. // SuperAdministrator access only
  355. if ((empty($conf->global->MAIN_MODULE_MULTICOMPANY)) || ($user->admin && !$user->entity))
  356. {
  357. print '<input class="flat" name="MAIN_MAIL_SMTPS_ID" size="32" value="' . $conf->global->MAIN_MAIL_SMTPS_ID . '">';
  358. }
  359. else
  360. {
  361. $htmltext = $langs->trans("ContactSuperAdminForChange");
  362. print $html->textwithpicto($conf->global->MAIN_MAIL_SMTPS_ID,$htmltext,1,'superadmin');
  363. print '<input type="hidden" name="MAIN_MAIL_SMTPS_ID" value="'.$conf->global->MAIN_MAIL_SMTPS_ID.'">';
  364. }
  365. print '</td></tr>';
  366. }
  367. // PW
  368. if ($conf->use_javascript_ajax || $conf->global->MAIN_MAIL_SENDMODE == 'smtps')
  369. {
  370. $var=!$var;
  371. print '<tr '.$bcdd[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>';
  372. // SuperAdministrator access only
  373. if ((empty($conf->global->MAIN_MODULE_MULTICOMPANY)) || ($user->admin && !$user->entity))
  374. {
  375. print '<input class="flat" name="MAIN_MAIL_SMTPS_PW" size="32" value="' . $conf->global->MAIN_MAIL_SMTPS_PW . '">';
  376. }
  377. else
  378. {
  379. $htmltext = $langs->trans("ContactSuperAdminForChange");
  380. print $html->textwithpicto($conf->global->MAIN_MAIL_SMTPS_PW,$htmltext,1,'superadmin');
  381. print '<input type="hidden" name="MAIN_MAIL_SMTPS_PW" value="'.$conf->global->MAIN_MAIL_SMTPS_PW.'">';
  382. }
  383. print '</td></tr>';
  384. }
  385. // TLS
  386. $var=!$var;
  387. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
  388. if ($conf->use_javascript_ajax || $conf->global->MAIN_MAIL_SENDMODE == 'smtps')
  389. {
  390. if (function_exists('openssl_open'))
  391. {
  392. print $html->selectyesno('MAIN_MAIL_EMAIL_TLS',$conf->global->MAIN_MAIL_EMAIL_TLS,1);
  393. }
  394. else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  395. }
  396. else print yn(0).' ('.$langs->trans("NotSupported").')';
  397. print '</td></tr>';
  398. // Separator
  399. $var=!$var;
  400. print '<tr '.$bc[$var].'><td colspan="2">&nbsp;</td></tr>';
  401. // From
  402. $var=!$var;
  403. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_EMAIL_FROM",ini_get('sendmail_from')?ini_get('sendmail_from'):$langs->transnoentities("Undefined")).'</td>';
  404. print '<td><input class="flat" name="MAIN_MAIL_EMAIL_FROM" size="32" value="' . $conf->global->MAIN_MAIL_EMAIL_FROM;
  405. print '"></td></tr>';
  406. // From
  407. $var=!$var;
  408. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_ERRORS_TO").'</td>';
  409. print '<td><input class="flat" name="MAIN_MAIL_ERRORS_TO" size="32" value="' . $conf->global->MAIN_MAIL_ERRORS_TO;
  410. print '"></td></tr>';
  411. // Autocopy to
  412. $var=!$var;
  413. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
  414. print '<td><input class="flat" name="MAIN_MAIL_AUTOCOPY_TO" size="32" value="' . $conf->global->MAIN_MAIL_AUTOCOPY_TO;
  415. print '"></td></tr>';
  416. print '</table>';
  417. print '<br><center>';
  418. print '<input class="button" type="submit" name="save" value="'.$langs->trans("Save").'">';
  419. print ' &nbsp; &nbsp; ';
  420. print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  421. print '</center>';
  422. print '</form>';
  423. print '<br>';
  424. }
  425. else
  426. {
  427. $var=true;
  428. print '<table class="noborder" width="100%">';
  429. print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  430. // Disable
  431. $var=!$var;
  432. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_DISABLE_ALL_MAILS").'</td><td>'.yn($conf->global->MAIN_DISABLE_ALL_MAILS).'</td></tr>';
  433. // Separator
  434. $var=!$var;
  435. print '<tr '.$bc[$var].'><td colspan="2">&nbsp;</td></tr>';
  436. // Method
  437. $var=!$var;
  438. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SENDMODE").'</td><td>';
  439. $text=$listofmethods[$conf->global->MAIN_MAIL_SENDMODE];
  440. if (empty($text)) $text=$langs->trans("Undefined").img_warning();
  441. print $text;
  442. print '</td></tr>';
  443. // Server
  444. $var=!$var;
  445. if ($linuxlike && ($conf->global->MAIN_MAIL_SENDMODE == 'mail' || $conf->global->MAIN_MAIL_SENDMODE == 'simplemail'))
  446. {
  447. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
  448. }
  449. else
  450. {
  451. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTP_SERVER",ini_get('SMTP')?ini_get('SMTP'):$langs->transnoentities("Undefined")).'</td><td>'.$conf->global->MAIN_MAIL_SMTP_SERVER.'</td></tr>';
  452. }
  453. // Port
  454. $var=!$var;
  455. if ($linuxlike && ($conf->global->MAIN_MAIL_SENDMODE == 'mail' || $conf->global->MAIN_MAIL_SENDMODE == 'simplemail'))
  456. {
  457. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT_NotAvailableOnLinuxLike").'</td><td>'.$langs->trans("SeeLocalSendMailSetup").'</td></tr>';
  458. }
  459. else
  460. {
  461. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTP_PORT",ini_get('smtp_port')?ini_get('smtp_port'):$langs->transnoentities("Undefined")).'</td><td>'.$conf->global->MAIN_MAIL_SMTP_PORT.'</td></tr>';
  462. }
  463. // SMTPS ID
  464. $var=!$var;
  465. if ($conf->global->MAIN_MAIL_SENDMODE == 'smtps')
  466. {
  467. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTPS_ID").'</td><td>'.$conf->global->MAIN_MAIL_SMTPS_ID.'</td></tr>';
  468. }
  469. // SMTPS PW
  470. $var=!$var;
  471. if ($conf->global->MAIN_MAIL_SENDMODE == 'smtps')
  472. {
  473. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_SMTPS_PW").'</td><td>'.$conf->global->MAIN_MAIL_SMTPS_PW.'</td></tr>';
  474. }
  475. // TLS
  476. $var=!$var;
  477. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_EMAIL_TLS").'</td><td>';
  478. if ($conf->global->MAIN_MAIL_SENDMODE == 'smtps')
  479. {
  480. if (function_exists('openssl_open'))
  481. {
  482. print yn($conf->global->MAIN_MAIL_EMAIL_TLS);
  483. }
  484. else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
  485. }
  486. else print yn(0).' ('.$langs->trans("NotSupported").')';
  487. print '</td></tr>';
  488. // Separator
  489. $var=!$var;
  490. print '<tr '.$bc[$var].'><td colspan="2">&nbsp;</td></tr>';
  491. // From
  492. $var=!$var;
  493. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_EMAIL_FROM",ini_get('sendmail_from')?ini_get('sendmail_from'):$langs->transnoentities("Undefined")).'</td>';
  494. print '<td>'.$conf->global->MAIN_MAIL_EMAIL_FROM;
  495. if (!empty($conf->global->MAIN_MAIL_EMAIL_FROM) && ! isValidEmail($conf->global->MAIN_MAIL_EMAIL_FROM)) print img_warning($langs->trans("ErrorBadEMail"));
  496. print '</td></tr>';
  497. // Errors To
  498. $var=!$var;
  499. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_ERRORS_TO").'</td>';
  500. print '<td>'.$conf->global->MAIN_MAIL_ERRORS_TO;
  501. if (!empty($conf->global->MAIN_MAIL_ERRORS_TO) && ! isValidEmail($conf->global->MAIN_MAIL_ERRORS_TO)) print img_warning($langs->trans("ErrorBadEMail"));
  502. print '</td></tr>';
  503. // Autocopy to
  504. $var=!$var;
  505. print '<tr '.$bc[$var].'><td>'.$langs->trans("MAIN_MAIL_AUTOCOPY_TO").'</td>';
  506. print '<td>'.$conf->global->MAIN_MAIL_AUTOCOPY_TO;
  507. if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO) && ! isValidEmail($conf->global->MAIN_MAIL_AUTOCOPY_TO)) print img_warning($langs->trans("ErrorBadEMail"));
  508. print '</td></tr>';
  509. print '</table>';
  510. if ($linuxlike && $conf->global->MAIN_MAIL_SENDMODE == 'mail')
  511. {
  512. $sendmailoption=ini_get('mail.force_extra_parameters');
  513. //print 'x'.$sendmailoption;
  514. if (empty($sendmailoption) || ! preg_match('/ba/',$sendmailoption))
  515. {
  516. print '<br>'.info_admin($langs->trans("SendmailOptionNotComplete"));
  517. }
  518. }
  519. // Boutons actions
  520. print '<div class="tabsAction">';
  521. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
  522. if ($conf->global->MAIN_MAIL_SENDMODE != 'mail' || ! $linuxlike)
  523. {
  524. if (function_exists('fsockopen') && $port && $server)
  525. {
  526. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testconnect">'.$langs->trans("DoTestServerAvailability").'</a>';
  527. }
  528. }
  529. else
  530. {
  531. print '<a class="butActionRefused" href="#" title="'.$langs->trans("FeatureNotAvailableOnLinux").'">'.$langs->trans("DoTestServerAvailability").'</a>';
  532. }
  533. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=test&amp;mode=init">'.$langs->trans("DoTestSend").'</a>';
  534. if ($conf->fckeditor->enabled)
  535. {
  536. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=testhtml&amp;mode=init">'.$langs->trans("DoTestSendHTML").'</a>';
  537. }
  538. print '</div>';
  539. // Run the test to connect
  540. if ($_GET["action"] == 'testconnect')
  541. {
  542. print '<br>';
  543. print_titre($langs->trans("DoTestServerAvailability"));
  544. // If we use SSL/TLS
  545. if (! empty($conf->global->MAIN_MAIL_EMAIL_TLS) && function_exists('openssl_open')) $server='ssl://'.$server;
  546. include_once(DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
  547. $mail = new CMailFile('','','','');
  548. $result=$mail->check_server_port($server,$port);
  549. if ($result) print '<div class="ok">'.$langs->trans("ServerAvailableOnIPOrPort",$server,$port).'</div>';
  550. else
  551. {
  552. print '<div class="error">'.$langs->trans("ServerNotAvailableOnIPOrPort",$server,$port);
  553. if ($mail->error) print ' - '.$langs->convToOutputCharset($mail->error,'ISO-8859-1');
  554. print '</div>';
  555. }
  556. print '<br>';
  557. }
  558. // Affichage formulaire de TEST simple
  559. if ($_GET["action"] == 'test')
  560. {
  561. print '<br>';
  562. print_titre($langs->trans("DoTestSend"));
  563. // Cree l'objet formulaire mail
  564. include_once(DOL_DOCUMENT_ROOT."/core/class/html.formmail.class.php");
  565. $formmail = new FormMail($db);
  566. $formmail->fromname = (isset($_POST['fromname'])?$_POST['fromname']:$conf->global->MAIN_MAIL_EMAIL_FROM);
  567. $formmail->frommail = (isset($_POST['frommail'])?$_POST['frommail']:$conf->global->MAIN_MAIL_EMAIL_FROM);
  568. $formmail->withfromreadonly=0;
  569. $formmail->withsubstit=0;
  570. $formmail->withfrom=1;
  571. $formmail->witherrorsto=1;
  572. $formmail->withto=(! empty($_POST['sendto'])?$_POST['sendto']:($user->email?$user->email:1));
  573. $formmail->withtocc=(! empty($_POST['sendtocc'])?$_POST['sendtocc']:1); // ! empty to keep field if empty
  574. $formmail->withtoccc=(! empty($_POST['sendtoccc'])?$_POST['sendtoccc']:1); // ! empty to keep field if empty
  575. $formmail->withtopic=(isset($_POST['subject'])?$_POST['subject']:$langs->trans("Test"));
  576. $formmail->withtopicreadonly=0;
  577. $formmail->withfile=2;
  578. $formmail->withbody=(isset($_POST['message'])?$_POST['message']:$langs->trans("PredefinedMailTest"));
  579. $formmail->withbodyreadonly=0;
  580. $formmail->withcancel=1;
  581. $formmail->withdeliveryreceipt=1;
  582. $formmail->withfckeditor=0;
  583. // Tableau des substitutions
  584. $formmail->substit=$substitutionarrayfortest;
  585. // Tableau des parametres complementaires du post
  586. $formmail->param["action"]="send";
  587. $formmail->param["models"]="body";
  588. $formmail->param["mailid"]=0;
  589. $formmail->param["returnurl"]=$_SERVER["PHP_SELF"];
  590. // Init list of files
  591. if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init')
  592. {
  593. $formmail->clear_attached_files();
  594. }
  595. $formmail->show_form('addfile','removefile');
  596. print '<br>';
  597. }
  598. // Affichage formulaire de TEST HTML
  599. if ($_GET["action"] == 'testhtml')
  600. {
  601. print '<br>';
  602. print_titre($langs->trans("DoTestSendHTML"));
  603. // Cree l'objet formulaire mail
  604. include_once(DOL_DOCUMENT_ROOT."/core/class/html.formmail.class.php");
  605. $formmail = new FormMail($db);
  606. $formmail->fromname = (isset($_POST['fromname'])?$_POST['fromname']:$conf->global->MAIN_MAIL_EMAIL_FROM);
  607. $formmail->frommail = (isset($_POST['frommail'])?$_POST['frommail']:$conf->global->MAIN_MAIL_EMAIL_FROM);
  608. $formmail->withfromreadonly=0;
  609. $formmail->withsubstit=0;
  610. $formmail->withfrom=1;
  611. $formmail->witherrorsto=1;
  612. $formmail->withto=(! empty($_POST['sendto'])?$_POST['sendto']:($user->email?$user->email:1));
  613. $formmail->withtocc=(! empty($_POST['sendtocc'])?$_POST['sendtocc']:1); // ! empty to keep field if empty
  614. $formmail->withtoccc=(! empty($_POST['sendtoccc'])?$_POST['sendtoccc']:1); // ! empty to keep field if empty
  615. $formmail->withtopic=(isset($_POST['subject'])?$_POST['subject']:$langs->trans("Test"));
  616. $formmail->withtopicreadonly=0;
  617. $formmail->withfile=2;
  618. $formmail->withbody=(isset($_POST['message'])?$_POST['message']:$langs->trans("PredefinedMailTestHtml"));
  619. //$formmail->withbody='Test <b>aaa</b> __LOGIN__';
  620. $formmail->withbodyreadonly=0;
  621. $formmail->withcancel=1;
  622. $formmail->withdeliveryreceipt=1;
  623. $formmail->withfckeditor=1;
  624. // Tableau des substitutions
  625. $formmail->substit=$substitutionarrayfortest;
  626. // Tableau des parametres complementaires du post
  627. $formmail->param["action"]="sendhtml";
  628. $formmail->param["models"]="body";
  629. $formmail->param["mailid"]=0;
  630. $formmail->param["returnurl"]=$_SERVER["PHP_SELF"];
  631. // Init list of files
  632. if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init')
  633. {
  634. $formmail->clear_attached_files();
  635. }
  636. $formmail->show_form('addfilehtml','removefilehtml');
  637. print '<br>';
  638. }
  639. }
  640. $db->close();
  641. llxFooter();
  642. ?>