actions_sendmails.inc.php 19 KB

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