actions_sendmails.inc.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. <?php
  2. /* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
  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 3 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 <https://www.gnu.org/licenses/>.
  17. * or see https://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/actions_sendmails.inc.php
  21. * \brief Code for actions on sending mails from object page
  22. */
  23. // $mysoc must be defined
  24. // $id must be defined
  25. // $paramname may be defined
  26. // $autocopy may be defined (used to know the automatic BCC to add)
  27. // $triggersendname must be set (can be '')
  28. // $actiontypecode can be set
  29. // $object and $uobject may be defined
  30. /*
  31. * Add file in email form
  32. */
  33. if (GETPOST('addfile', 'alpha')) {
  34. $trackid = GETPOST('trackid', 'aZ09');
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  36. // Set tmp user directory
  37. $vardir = $conf->user->dir_output."/".$user->id;
  38. $upload_dir_tmp = $vardir.'/temp'; // TODO Add $keytoavoidconflict in upload_dir path
  39. dol_add_file_process($upload_dir_tmp, 1, 0, 'addedfile', '', null, $trackid, 0);
  40. $action = 'presend';
  41. }
  42. /*
  43. * Remove file in email form
  44. */
  45. if (GETPOST('removedfile') && !GETPOST('removAll')) {
  46. $trackid = GETPOST('trackid', 'aZ09');
  47. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  48. // Set tmp user directory
  49. $vardir = $conf->user->dir_output."/".$user->id;
  50. $upload_dir_tmp = $vardir.'/temp'; // TODO Add $keytoavoidconflict in upload_dir path
  51. // TODO Delete only files that was uploaded from email form. This can be addressed by adding the trackid into the temp path then changing donotdeletefile to 2 instead of 1 to say "delete only if into temp dir"
  52. // GETPOST('removedfile','alpha') is position of file into $_SESSION["listofpaths"...] array.
  53. dol_remove_file_process(GETPOST('removedfile', 'alpha'), 0, 1, $trackid); // We do not delete because if file is the official PDF of doc, we don't want to remove it physically
  54. $action = 'presend';
  55. }
  56. /*
  57. * Remove all files in email form
  58. */
  59. if (GETPOST('removAll', 'alpha')) {
  60. $trackid = GETPOST('trackid', 'aZ09');
  61. $listofpaths = array();
  62. $listofnames = array();
  63. $listofmimes = array();
  64. $keytoavoidconflict = empty($trackid) ? '' : '-'.$trackid;
  65. if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) {
  66. $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
  67. }
  68. if (!empty($_SESSION["listofnames".$keytoavoidconflict])) {
  69. $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]);
  70. }
  71. if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) {
  72. $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]);
  73. }
  74. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  75. $formmail = new FormMail($db);
  76. $formmail->trackid = $trackid;
  77. foreach ($listofpaths as $key => $value) {
  78. $pathtodelete = $value;
  79. $filetodelete = $listofnames[$key];
  80. $result = dol_delete_file($pathtodelete, 1); // Delete uploded Files
  81. $langs->load("other");
  82. setEventMessages($langs->trans("FileWasRemoved", $filetodelete), null, 'mesgs');
  83. $formmail->remove_attached_files($key); // Update Session
  84. }
  85. }
  86. /*
  87. * Send mail
  88. */
  89. if (($action == 'send' || $action == 'relance') && !GETPOST('addfile') && !GETPOST('removAll') && !GETPOST('removedfile') && !GETPOST('cancel') && !GETPOST('modelselected')) {
  90. if (empty($trackid)) {
  91. $trackid = GETPOST('trackid', 'aZ09');
  92. }
  93. // Set tmp user directory (used to convert images embedded as img src=data:image)
  94. $vardir = $conf->user->dir_output."/".$user->id;
  95. $upload_dir_tmp = $vardir.'/temp'; // TODO Add $keytoavoidconflict in upload_dir path
  96. $subject = '';
  97. //$actionmsg = '';
  98. $actionmsg2 = '';
  99. $langs->load('mails');
  100. if (is_object($object)) {
  101. $result = $object->fetch($id);
  102. $sendtosocid = 0; // Id of related thirdparty
  103. if (method_exists($object, "fetch_thirdparty") && !in_array($object->element, array('member', 'user', 'expensereport', 'societe', 'contact'))) {
  104. $resultthirdparty = $object->fetch_thirdparty();
  105. $thirdparty = $object->thirdparty;
  106. if (is_object($thirdparty)) {
  107. $sendtosocid = $thirdparty->id;
  108. }
  109. } elseif ($object->element == 'member' || $object->element == 'user') {
  110. $thirdparty = $object;
  111. if ($object->socid > 0) {
  112. $sendtosocid = $object->socid;
  113. }
  114. } elseif ($object->element == 'expensereport') {
  115. $tmpuser = new User($db);
  116. $tmpuser->fetch($object->fk_user_author);
  117. $thirdparty = $tmpuser;
  118. if ($object->socid > 0) {
  119. $sendtosocid = $object->socid;
  120. }
  121. } elseif ($object->element == 'societe') {
  122. $thirdparty = $object;
  123. if (is_object($thirdparty) && $thirdparty->id > 0) {
  124. $sendtosocid = $thirdparty->id;
  125. }
  126. } elseif ($object->element == 'contact') {
  127. $contact = $object;
  128. if ($contact->id > 0) {
  129. $contact->fetch_thirdparty();
  130. $thirdparty = $contact->thirdparty;
  131. if (is_object($thirdparty) && $thirdparty->id > 0) {
  132. $sendtosocid = $thirdparty->id;
  133. }
  134. }
  135. } else {
  136. dol_print_error('', "Use actions_sendmails.in.php for an element/object '".$object->element."' that is not supported");
  137. }
  138. if (is_object($hookmanager)) {
  139. $parameters = array();
  140. $reshook = $hookmanager->executeHooks('initSendToSocid', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  141. }
  142. } else {
  143. $thirdparty = $mysoc;
  144. }
  145. if ($result > 0) {
  146. $sendto = '';
  147. $sendtocc = '';
  148. $sendtobcc = '';
  149. $sendtoid = array();
  150. $sendtouserid = array();
  151. $sendtoccuserid = array();
  152. // Define $sendto
  153. $receiver = GETPOST('receiver', 'alphawithlgt');
  154. if (!is_array($receiver)) {
  155. if ($receiver == '-1') {
  156. $receiver = array();
  157. } else {
  158. $receiver = array($receiver);
  159. }
  160. }
  161. $tmparray = array();
  162. if (trim($_POST['sendto'])) {
  163. // Recipients are provided into free text field
  164. $tmparray[] = trim(GETPOST('sendto', 'alphawithlgt'));
  165. }
  166. if (isset($_POST['tomail']) && trim($_POST['tomail'])) {
  167. // Recipients are provided into free hidden text field
  168. $tmparray[] = trim(GETPOST('tomail', 'alphawithlgt'));
  169. }
  170. if (count($receiver) > 0) {
  171. // Recipient was provided from combo list
  172. foreach ($receiver as $key => $val) {
  173. if ($val == 'thirdparty') { // Key selected means current third party ('thirdparty' may be used for current member or current user too)
  174. $tmparray[] = dol_string_nospecial($thirdparty->getFullName($langs), ' ', array(",")).' <'.$thirdparty->email.'>';
  175. } elseif ($val == 'contact') { // Key selected means current contact
  176. $tmparray[] = dol_string_nospecial($contact->getFullName($langs), ' ', array(",")).' <'.$contact->email.'>';
  177. $sendtoid[] = $contact->id;
  178. } elseif ($val) { // $val is the Id of a contact
  179. $tmparray[] = $thirdparty->contact_get_property((int) $val, 'email');
  180. $sendtoid[] = ((int) $val);
  181. }
  182. }
  183. }
  184. if (getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
  185. $receiveruser = GETPOST('receiveruser', 'alphawithlgt');
  186. if (is_array($receiveruser) && count($receiveruser) > 0) {
  187. $fuserdest = new User($db);
  188. foreach ($receiveruser as $key => $val) {
  189. $tmparray[] = $fuserdest->user_get_property($val, 'email');
  190. $sendtouserid[] = $val;
  191. }
  192. }
  193. }
  194. $sendto = implode(',', $tmparray);
  195. // Define $sendtocc
  196. $receivercc = GETPOST('receivercc', 'alphawithlgt');
  197. if (!is_array($receivercc)) {
  198. if ($receivercc == '-1') {
  199. $receivercc = array();
  200. } else {
  201. $receivercc = array($receivercc);
  202. }
  203. }
  204. $tmparray = array();
  205. if (trim($_POST['sendtocc'])) {
  206. $tmparray[] = trim(GETPOST('sendtocc', 'alphawithlgt'));
  207. }
  208. if (count($receivercc) > 0) {
  209. foreach ($receivercc as $key => $val) {
  210. if ($val == 'thirdparty') { // Key selected means current thirdparty (may be usd for current member or current user too)
  211. // Recipient was provided from combo list
  212. $tmparray[] = dol_string_nospecial($thirdparty->name, ' ', array(",")).' <'.$thirdparty->email.'>';
  213. } elseif ($val == 'contact') { // Key selected means current contact
  214. // Recipient was provided from combo list
  215. $tmparray[] = dol_string_nospecial($contact->name, ' ', array(",")).' <'.$contact->email.'>';
  216. //$sendtoid[] = $contact->id; TODO Add also id of contact in CC ?
  217. } elseif ($val) { // $val is the Id of a contact
  218. $tmparray[] = $thirdparty->contact_get_property((int) $val, 'email');
  219. //$sendtoid[] = ((int) $val); TODO Add also id of contact in CC ?
  220. }
  221. }
  222. }
  223. if (getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
  224. $receiverccuser = GETPOST('receiverccuser', 'alphawithlgt');
  225. if (is_array($receiverccuser) && count($receiverccuser) > 0) {
  226. $fuserdest = new User($db);
  227. foreach ($receiverccuser as $key => $val) {
  228. $tmparray[] = $fuserdest->user_get_property($val, 'email');
  229. $sendtoccuserid[] = $val;
  230. }
  231. }
  232. }
  233. $sendtocc = implode(',', $tmparray);
  234. if (dol_strlen($sendto)) {
  235. // Define $urlwithroot
  236. $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
  237. $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  238. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  239. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  240. $langs->load("commercial");
  241. $reg = array();
  242. $fromtype = GETPOST('fromtype', 'alpha');
  243. if ($fromtype === 'robot') {
  244. $from = dol_string_nospecial($conf->global->MAIN_MAIL_EMAIL_FROM, ' ', array(",")).' <' . getDolGlobalString('MAIN_MAIL_EMAIL_FROM').'>';
  245. } elseif ($fromtype === 'user') {
  246. // MMI Hack : Email sender name
  247. if (!empty($conf->mmicrm->enabled) && !empty($conf->global->MMICRM_USER_MAILFROM_NAME) && !empty($user->array_options['options_email_sender_name']))
  248. $from = dol_string_nospecial($user->array_options['options_email_sender_name'], ' ', array(",")).' <'.$user->email.'>';
  249. else
  250. $from = dol_string_nospecial($user->getFullName($langs), ' ', array(",")).' <'.$user->email.'>';
  251. } elseif ($fromtype === 'company') {
  252. $from = dol_string_nospecial($conf->global->MAIN_INFO_SOCIETE_NOM, ' ', array(",")).' <' . getDolGlobalString('MAIN_INFO_SOCIETE_MAIL').'>';
  253. } elseif (preg_match('/user_aliases_(\d+)/', $fromtype, $reg)) {
  254. $tmp = explode(',', $user->email_aliases);
  255. $from = trim($tmp[($reg[1] - 1)]);
  256. } elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) {
  257. $tmp = explode(',', getDolGlobalString('MAIN_INFO_SOCIETE_MAIL_ALIASES'));
  258. $from = trim($tmp[($reg[1] - 1)]);
  259. } elseif (preg_match('/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
  260. $sql = 'SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile';
  261. $sql .= ' WHERE rowid = '.(int) $reg[1];
  262. $resql = $db->query($sql);
  263. $obj = $db->fetch_object($resql);
  264. if ($obj) {
  265. $from = dol_string_nospecial($obj->label, ' ', array(",")).' <'.$obj->email.'>';
  266. }
  267. } elseif (preg_match('/from_template_(\d+)/', $fromtype, $reg)) {
  268. $sql = 'SELECT rowid, email_from FROM '.MAIN_DB_PREFIX.'c_email_templates';
  269. $sql .= ' WHERE rowid = '.(int) $reg[1];
  270. $resql = $db->query($sql);
  271. $obj = $db->fetch_object($resql);
  272. if ($obj) {
  273. $from = $obj->email_from;
  274. }
  275. } else {
  276. $from = dol_string_nospecial(GETPOST('fromname'), ' ', array(",")).' <'.GETPOST('frommail').'>';
  277. }
  278. $replyto = dol_string_nospecial(GETPOST('replytoname'), ' ', array(",")).' <'.GETPOST('replytomail').'>';
  279. $message = GETPOST('message', 'restricthtml');
  280. $subject = GETPOST('subject', 'restricthtml');
  281. // Make a change into HTML code to allow to include images from medias directory with an external reabable URL.
  282. // <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&amp;entity=1&amp;file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
  283. // become
  284. // <img alt="" src="'.$urlwithroot.'viewimage.php?modulepart=medias&amp;entity=1&amp;file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
  285. $message = preg_replace('/(<img.*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/>)/', '\1'.$urlwithroot.'/viewimage.php\2modulepart=medias\3file=\4\5', $message);
  286. $sendtobcc = GETPOST('sendtoccc');
  287. // Autocomplete the $sendtobcc
  288. // $autocopy can be MAIN_MAIL_AUTOCOPY_PROPOSAL_TO, MAIN_MAIL_AUTOCOPY_ORDER_TO, MAIN_MAIL_AUTOCOPY_INVOICE_TO, MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO...
  289. if (!empty($autocopy)) {
  290. $sendtobcc .= (empty($conf->global->$autocopy) ? '' : (($sendtobcc ? ", " : "") . getDolGlobalString($autocopy)));
  291. }
  292. $deliveryreceipt = GETPOST('deliveryreceipt');
  293. if ($action == 'send' || $action == 'relance') {
  294. $actionmsg2 = $langs->transnoentities('MailSentByTo', CMailFile::getValidAddress($from, 4, 0, 1), CMailFile::getValidAddress($sendto, 4, 0, 1));
  295. /*if ($message) {
  296. $actionmsg = $langs->transnoentities('MailFrom').': '.dol_escape_htmltag($from);
  297. $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTo').': '.dol_escape_htmltag($sendto));
  298. if ($sendtocc) {
  299. $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".dol_escape_htmltag($sendtocc));
  300. }
  301. $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
  302. $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
  303. $actionmsg = dol_concatdesc($actionmsg, $message);
  304. }*/
  305. }
  306. // Create form object
  307. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  308. $formmail = new FormMail($db);
  309. $formmail->trackid = $trackid; // $trackid must be defined
  310. $attachedfiles = $formmail->get_attached_files();
  311. $filepath = $attachedfiles['paths'];
  312. $filename = $attachedfiles['names'];
  313. $mimetype = $attachedfiles['mimes'];
  314. // Make substitution in email content
  315. $substitutionarray = getCommonSubstitutionArray($langs, 0, null, $object);
  316. $substitutionarray['__EMAIL__'] = $sendto;
  317. $substitutionarray['__CHECK_READ__'] = (is_object($object) && is_object($object->thirdparty)) ? '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag=undefined&securitykey='.dol_hash(getDolGlobalString('MAILING_EMAIL_UNSUBSCRIBE_KEY')."-undefined", 'md5').'" width="1" height="1" style="width:1px;height:1px" border="0"/>' : '';
  318. $parameters = array('mode'=>'formemail');
  319. complete_substitutions_array($substitutionarray, $langs, $object, $parameters);
  320. $subject = make_substitutions($subject, $substitutionarray);
  321. $message = make_substitutions($message, $substitutionarray);
  322. if (is_object($object) && method_exists($object, 'makeSubstitution')) {
  323. $subject = $object->makeSubstitution($subject);
  324. $message = $object->makeSubstitution($message);
  325. }
  326. // Send mail (substitutionarray must be done just before this)
  327. if (empty($sendcontext)) {
  328. $sendcontext = 'standard';
  329. }
  330. $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1, '', '', $trackid, '', $sendcontext, '', $upload_dir_tmp);
  331. if (!empty($mailfile->error) || !empty($mailfile->errors)) {
  332. setEventMessages($mailfile->error, $mailfile->errors, 'errors');
  333. $action = 'presend';
  334. } else {
  335. $result = $mailfile->sendfile();
  336. if ($result) {
  337. // Initialisation of datas of object to call trigger
  338. if (is_object($object)) {
  339. if (empty($actiontypecode)) {
  340. $actiontypecode = 'AC_OTH_AUTO'; // Event insert into agenda automatically
  341. }
  342. $object->socid = $sendtosocid; // To link to a company
  343. $object->sendtoid = $sendtoid; // To link to contact-addresses. This is an array.
  344. $object->actiontypecode = $actiontypecode; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
  345. $object->actionmsg = $message; // Long text
  346. $object->actionmsg2 = $actionmsg2; // Short text ($langs->transnoentities('MailSentBy')...);
  347. if (getDolGlobalString('MAIN_MAIL_REPLACE_EVENT_TITLE_BY_EMAIL_SUBJECT')) {
  348. $object->actionmsg2 = $subject; // Short text
  349. }
  350. $object->trackid = $trackid;
  351. $object->fk_element = $object->id;
  352. $object->elementtype = $object->element;
  353. if (is_array($attachedfiles) && count($attachedfiles) > 0) {
  354. $object->attachedfiles = $attachedfiles;
  355. }
  356. if (is_array($sendtouserid) && count($sendtouserid) > 0 && getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
  357. $object->sendtouserid = $sendtouserid;
  358. }
  359. $object->email_msgid = $mailfile->msgid; // @todo Set msgid into $mailfile after sending
  360. $object->email_from = $from;
  361. $object->email_subject = $subject;
  362. $object->email_to = $sendto;
  363. $object->email_tocc = $sendtocc;
  364. $object->email_tobcc = $sendtobcc;
  365. $object->email_subject = $subject;
  366. // Call of triggers (you should have set $triggersendname to execute trigger. $trigger_name is deprecated)
  367. if (!empty($triggersendname) || !empty($trigger_name)) {
  368. // Call trigger
  369. $result = $object->call_trigger(empty($triggersendname) ? $trigger_name : $triggersendname, $user);
  370. if ($result < 0) {
  371. $error++;
  372. }
  373. // End call triggers
  374. if ($error) {
  375. setEventMessages($object->error, $object->errors, 'errors');
  376. }
  377. }
  378. // End call of triggers
  379. }
  380. // Redirect here
  381. // This avoid sending mail twice if going out and then back to page
  382. $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($sendto, 2));
  383. setEventMessages($mesg, null, 'mesgs');
  384. $moreparam = '';
  385. if (isset($paramname2) || isset($paramval2)) {
  386. $moreparam .= '&'.($paramname2 ? $paramname2 : 'mid').'='.$paramval2;
  387. }
  388. header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname ? $paramname : 'id').'='.(is_object($object) ? $object->id : '').$moreparam);
  389. exit;
  390. } else {
  391. $langs->load("other");
  392. $mesg = '<div class="error">';
  393. if (!empty($mailfile->error) || !empty($mailfile->errors)) {
  394. $mesg .= $langs->transnoentities('ErrorFailedToSendMail', dol_escape_htmltag($from), dol_escape_htmltag($sendto));
  395. if (!empty($mailfile->error)) {
  396. $mesg .= '<br>'.$mailfile->error;
  397. }
  398. if (!empty($mailfile->errors) && is_array($mailfile->errors)) {
  399. $mesg .= '<br>'.implode('<br>', $mailfile->errors);
  400. }
  401. } else {
  402. $mesg .= $langs->transnoentities('ErrorFailedToSendMail', dol_escape_htmltag($from), dol_escape_htmltag($sendto));
  403. if (getDolGlobalString('MAIN_DISABLE_ALL_MAILS')) {
  404. $mesg .= '<br>Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
  405. } else {
  406. $mesg .= '<br>Unkown Error, please refers to your administrator';
  407. }
  408. }
  409. $mesg .= '</div>';
  410. setEventMessages($mesg, null, 'warnings');
  411. $action = 'presend';
  412. }
  413. }
  414. } else {
  415. $langs->load("errors");
  416. setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("MailTo")), null, 'warnings');
  417. dol_syslog('Try to send email with no recipient defined', LOG_WARNING);
  418. $action = 'presend';
  419. }
  420. } else {
  421. $langs->load("errors");
  422. setEventMessages($langs->trans('ErrorFailedToReadObject', $object->element), null, 'errors');
  423. dol_syslog('Failed to read data of object id='.$object->id.' element='.$object->element);
  424. $action = 'presend';
  425. }
  426. }