actions_sendmails.inc.php 20 KB

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