dolibarr 24.0.0-beta
actions_sendmails.inc.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
5* Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
6*
7* This program is free software; you can redistribute it and/or modify
8* it under the terms of the GNU General Public License as published by
9* the Free Software Foundation; either version 3 of the License, or
10* (at your option) any later version.
11*
12* This program is distributed in the hope that it will be useful,
13* but WITHOUT ANY WARRANTY; without even the implied warranty of
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15* GNU General Public License for more details.
16*
17* You should have received a copy of the GNU General Public License
18* along with this program. If not, see <https://www.gnu.org/licenses/>.
19* or see https://www.gnu.org/
20*/
21
48'
49@phan-var-force Societe $mysoc
50@phan-var-force CommonObject $object
51@phan-var-force int $error
52';
53
54
55/*
56 * Add file in email form
57 */
58if (GETPOST('addfile', 'alpha')) {
59 $trackid = GETPOST('trackid', 'aZ09');
60
61 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
62
63 // Set tmp user directory
64 $vardir = $conf->user->dir_output."/".$user->id;
65 $upload_dir_tmp = $vardir.'/temp'; // TODO Add $keytoavoidconflict in upload_dir path
66
67 dol_add_file_process($upload_dir_tmp, 1, 0, 'addedfile', '', null, $trackid, 0);
68 $action = 'presend';
69}
70
71/*
72 * Remove file in email form
73 */
74if (GETPOST('removedfile') && !GETPOST('removeAll')) {
75 $trackid = GETPOST('trackid', 'aZ09');
76
77 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
78
79 // Set tmp user directory
80 $vardir = $conf->user->dir_output."/".$user->id;
81 $upload_dir_tmp = $vardir.'/temp'; // TODO Add $keytoavoidconflict in upload_dir path
82
83 // 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"
84 // GETPOST('removedfile','alpha') is position of file into $_SESSION["listofpaths"...] array.
85 dol_remove_file_process(GETPOSTINT('removedfile'), 0, 1, $trackid); // We do not delete because if file is the official PDF of doc, we don't want to remove it physically
86 $action = 'presend';
87}
88
89/*
90 * Remove all files in email form
91 */
92if (GETPOST('removeAll', 'alpha')) {
93 $trackid = GETPOST('trackid', 'aZ09');
94
95 $listofpaths = array();
96 $listofnames = array();
97 $listofmimes = array();
98 $keytoavoidconflict = empty($trackid) ? '' : '-'.$trackid;
99 if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) {
100 $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
101 }
102 if (!empty($_SESSION["listofnames".$keytoavoidconflict])) {
103 $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]);
104 }
105 if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) {
106 $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]);
107 }
108
109 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
110 $formmail = new FormMail($db);
111 $formmail->trackid = $trackid;
112
113 foreach ($listofpaths as $key => $value) {
114 $pathtodelete = $value;
115 $filetodelete = $listofnames[$key];
116 $result = dol_delete_file($pathtodelete, 1); // Delete uploaded Files
117
118 $langs->load("other");
119 setEventMessages($langs->trans("FileWasRemoved", $filetodelete), null, 'mesgs');
120
121 $formmail->remove_attached_files($key); // Update Session
122 }
123}
124
125/*
126 * Send mail
127 */
128if (($action == 'send' || $action == 'relance') && !GETPOST('addfile') && !GETPOST('removeAll') && !GETPOST('removedfile') && !GETPOST('cancel') && !GETPOST('modelselected')) {
129 if (empty($trackid)) {
130 $trackid = GETPOST('trackid', 'aZ09');
131 }
132
133 // Set tmp user directory (used to convert images embedded as img src=data:image)
134 $vardir = $conf->user->dir_output."/".$user->id;
135 $upload_dir_tmp = $vardir.'/temp'; // TODO Add $keytoavoidconflict in upload_dir path
136
137 $subject = '';
138 //$actionmsg = '';
139 $actionmsg2 = '';
140 $thirdparty = null;
141 $contact = null;
142 $result = 0;
143
144 $langs->load('mails');
145
146 $sendtosocid = 0; // Id of related thirdparty
147
148 if (is_object($object)) {
149 $result = $object->fetch($id);
150
151 if (method_exists($object, "fetch_thirdparty") && !in_array($object->element, array('member', 'user', 'expensereport', 'societe', 'contact'))) {
152 $object->fetch_thirdparty();
153 $thirdparty = $object->thirdparty;
154 if (is_object($thirdparty)) {
155 $sendtosocid = $thirdparty->id;
156 }
157 } elseif ($object->element == 'member' || $object->element == 'user') {
158 '@phan-var-force Adherent|User $object';
159 $thirdparty = $object;
160 if ($object->socid > 0) {
161 $sendtosocid = $object->socid;
162 }
163 } elseif ($object->element == 'expensereport') {
164 '@phan-var-force ExpenseReport $object';
165 $tmpuser = new User($db);
166 $tmpuser->fetch($object->fk_user_author);
167 $thirdparty = $tmpuser;
168 if ($object->socid > 0) {
169 $sendtosocid = $object->socid;
170 }
171 } elseif ($object->element == 'societe') {
172 '@phan-var-force Societe $object';
173 $thirdparty = $object;
174 if (is_object($thirdparty) && $thirdparty->id > 0) {
175 $sendtosocid = $thirdparty->id;
176 }
177 } elseif ($object->element == 'contact') {
178 '@phan-var-force Contact $object';
179 $contact = $object;
180 if ($contact->id > 0) {
181 $contact->fetch_thirdparty();
182 $thirdparty = $contact->thirdparty;
183 if (is_object($thirdparty) && $thirdparty->id > 0) {
184 $sendtosocid = $thirdparty->id;
185 }
186 }
187 } else {
188 dol_print_error(null, "Use actions_sendmails.in.php for an element/object '".$object->element."' that is not supported");
189 }
190
191 if (is_object($hookmanager)) {
192 $parameters = array();
193 $reshook = $hookmanager->executeHooks('initSendToSocid', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
194 }
195 } else {
196 $thirdparty = $mysoc;
197 $result = 1; // No object to fetch (e.g. Setup -> Emails -> send test email): consider OK
198 }
199
200 if ($result > 0) {
201 $from = '';
202 $sendto = '';
203 $sendtocc = '';
204 $sendtobcc = '';
205 $sendtoid = array();
206 $sendtouserid = array();
207 $sendtoccuserid = array();
208
209 // Define $sendto
210 $receiver = GETPOST('receiver', 'alphawithlgt');
211 if (!is_array($receiver)) {
212 if ($receiver == '-1') {
213 $receiver = array();
214 } else {
215 $receiver = array($receiver);
216 }
217 }
218
219 $tmparray = array();
220 if (trim(GETPOST('sendto', 'alphawithlgt'))) {
221 // Recipients are provided into free text field
222 $tmparray[] = trim(GETPOST('sendto', 'alphawithlgt'));
223 }
224
225 if (trim(GETPOST('tomail', 'alphawithlgt'))) {
226 // Recipients are provided into free hidden text field
227 $tmparray[] = trim(GETPOST('tomail', 'alphawithlgt'));
228 }
229
230 if (count($receiver) > 0) {
231 // Recipient was provided from combo list
232 foreach ($receiver as $key => $val) {
233 if ($val == 'thirdparty') { // Key selected means current third party ('thirdparty' may be used for current member or current user too)
234 $thirdpartyEmail = (is_object($thirdparty) && !empty($thirdparty->email)) ? (string) $thirdparty->email : '';
235 if ($thirdpartyEmail !== '') {
236 $thirdpartyLabel = '';
237 if (is_object($thirdparty)) {
238 if (method_exists($thirdparty, 'getFullName')) {
239 $thirdpartyLabel = (string) $thirdparty->getFullName($langs);
240 } elseif (!empty($thirdparty->name)) {
241 $thirdpartyLabel = (string) $thirdparty->name;
242 } elseif (!empty($thirdparty->nom)) {
243 $thirdpartyLabel = (string) $thirdparty->nom;
244 }
245 }
246 if ($thirdpartyLabel !== '') {
247 $tmparray[] = dol_string_nospecial($thirdpartyLabel, ' ', array(",")).' <'.$thirdpartyEmail.'>';
248 } else {
249 $tmparray[] = $thirdpartyEmail;
250 }
251 }
252 } elseif ($val == 'contact') { // Key selected means current contact
253 $tmparray[] = dol_string_nospecial($contact->getFullName($langs), ' ', array(",")).' <'.$contact->email.'>';
254 $sendtoid[] = $contact->id;
255 } elseif ($val && $object->element == 'project' && empty($object->socid)) { // $val is the Id of a contact
256 $contact = new Contact($db);
257 $ret = $contact->fetch((int) $val);
258 if ($ret > 0 && !empty($contact->socid)) {
259 $thirdparty = new Societe($db);
260 $thirdparty->fetch($contact->socid);
261 $tmparray[] = $thirdparty->contact_get_property((int) $val, 'email');
262 $sendtoid[] = ((int) $val);
263 }
264 } elseif ($val) { // $val is the Id of a contact
265 $tmparray[] = $thirdparty->contact_get_property((int) $val, 'email');
266 $sendtoid[] = ((int) $val);
267 }
268 }
269 }
270
271 if (getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
272 $receiveruser = GETPOST('receiveruser', 'alphawithlgt');
273 if (is_array($receiveruser) && count($receiveruser) > 0) {
274 $fuserdest = new User($db);
275 foreach ($receiveruser as $key => $val) {
276 $tmparray[] = $fuserdest->user_get_property($val, 'email');
277 $sendtouserid[] = $val;
278 }
279 }
280 }
281
282 $sendto = implode(',', $tmparray);
283
284 // Define $sendtocc
285 $receivercc = GETPOST('receivercc', 'alphawithlgt');
286 if (!is_array($receivercc)) {
287 if ($receivercc == '-1') {
288 $receivercc = array();
289 } else {
290 $receivercc = array($receivercc);
291 }
292 }
293 $tmparray = array();
294 if (trim(GETPOST('sendtocc', 'alphawithlgt'))) {
295 $tmparray[] = trim(GETPOST('sendtocc', 'alphawithlgt'));
296 }
297 if (count($receivercc) > 0) {
298 foreach ($receivercc as $key => $val) {
299 if ($val == 'thirdparty') { // Key selected means current thirdparty (may be usd for current member or current user too)
300 // Recipient was provided from combo list
301 $tmparray[] = dol_string_nospecial((string) $thirdparty->name, ' ', array(",")).' <'.$thirdparty->email.'>';
302 } elseif ($val == 'contact') { // Key selected means current contact
303 // Recipient was provided from combo list
304 $tmparray[] = dol_string_nospecial((string) $contact->name, ' ', array(",")).' <'.$contact->email.'>';
305 //$sendtoid[] = $contact->id; TODO Add also id of contact in CC ?
306 } elseif ($val) { // $val is the Id of a contact
307 $tmparray[] = $thirdparty->contact_get_property((int) $val, 'email');
308 //$sendtoid[] = ((int) $val); TODO Add also id of contact in CC ?
309 }
310 }
311 }
312 if (getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
313 $receiverccuser = GETPOST('receiverccuser', 'alphawithlgt');
314
315 if (is_array($receiverccuser) && count($receiverccuser) > 0) {
316 $fuserdest = new User($db);
317 foreach ($receiverccuser as $key => $val) {
318 $tmparray[] = $fuserdest->user_get_property($val, 'email');
319 $sendtoccuserid[] = $val;
320 }
321 }
322 }
323 $sendtocc = implode(',', $tmparray);
324
325 if (dol_strlen($sendto)) {
326 // Define $urlwithroot
327 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
328 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
329 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
330
331 require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
332
333 $langs->load("commercial");
334
335 $reg = array();
336 $fromtype = GETPOST('fromtype', 'alpha');
337 $emailsendersignature = '';
338 if ($fromtype === 'robot') {
339 $from = dol_string_nospecial(getDolGlobalString('MAIN_MAIL_EMAIL_FROM'), ' ', array(",")).' <' . getDolGlobalString('MAIN_MAIL_EMAIL_FROM').'>';
340 } elseif ($fromtype === 'user') {
341 $from = dol_string_nospecial($user->getFullName($langs), ' ', array(",")).' <'.$user->email.'>';
342 } elseif ($fromtype === 'company') {
343 $from = dol_string_nospecial(getDolGlobalString('MAIN_INFO_SOCIETE_NOM'), ' ', array(",")).' <' . getDolGlobalString('MAIN_INFO_SOCIETE_MAIL').'>';
344 } elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) {
345 $tmp = explode(',', getDolGlobalString('MAIN_INFO_SOCIETE_MAIL_ALIASES'));
346 $from = trim($tmp[((int) $reg[1] - 1)]);
347 } elseif (preg_match('/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
348 $sql = 'SELECT rowid, label, email, signature FROM '.MAIN_DB_PREFIX.'c_email_senderprofile';
349 $sql .= ' WHERE rowid = '.(int) $reg[1];
350 $resql = $db->query($sql);
351 $obj = $db->fetch_object($resql);
352 if ($obj) {
353 $from = dol_string_nospecial($obj->label, ' ', array(",")).' <'.$obj->email.'>';
354 $emailsendersignature = $obj->signature;
355 }
356 } elseif (preg_match('/from_template_(\d+)/', $fromtype, $reg)) {
357 $sql = 'SELECT rowid, email_from FROM '.MAIN_DB_PREFIX.'c_email_templates';
358 $sql .= ' WHERE rowid = '.(int) $reg[1];
359 $resql = $db->query($sql);
360 $obj = $db->fetch_object($resql);
361 if ($obj) {
362 $from = $obj->email_from;
363 }
364 } else {
365 $from = dol_string_nospecial(GETPOST('fromname'), ' ', array(",")).' <'.GETPOST('frommail').'>';
366 }
367
368 $replyto = '';
369 if (GETPOST('replytomail')) {
370 $replyto = dol_string_nospecial(GETPOST('replytoname'), ' ', array(","));
371 $replyto .= ($replyto ? ' ' : '').'<'.GETPOST('replytomail').'>';
372 }
373
374 $message = GETPOST('message', 'restricthtml');
375 $subject = GETPOST('subject', 'restricthtml');
376
377 // Make a change into HTML code to allow to include images from medias directory with an external reabable URL.
378 // <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&amp;entity=1&amp;file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
379 // become
380 // <img alt="" src="'.$urlwithroot.'viewimage.php?modulepart=medias&amp;entity=1&amp;file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
381 $message = preg_replace('/(<img.*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/>)/', '\1'.$urlwithroot.'/viewimage.php\2modulepart=medias\3file=\4\5', $message);
382
383 $sendtobcc = GETPOST('sendtoccc', 'alphawithlgt');
384 // Autocomplete the $sendtobcc
385 // $autocopy can be MAIN_MAIL_AUTOCOPY_PROPOSAL_TO, MAIN_MAIL_AUTOCOPY_ORDER_TO, MAIN_MAIL_AUTOCOPY_INVOICE_TO, MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO...
386 if (!empty($autocopy)) {
387 $sendtobcc .= (getDolGlobalString($autocopy) ? (($sendtobcc ? ", " : "") . getDolGlobalString($autocopy)) : '');
388 }
389
390 $deliveryreceipt = GETPOSTINT('deliveryreceipt') ? 1 : 0;
391
392 if ($action == 'send' || $action == 'relance') {
393 $actionmsg2 = $langs->transnoentities('MailSentByTo', CMailFile::getValidAddress($from, 4, 0, 1), CMailFile::getValidAddress($sendto, 4, 0, 1));
394 /*if ($message) {
395 $actionmsg = $langs->transnoentities('MailFrom').': '.dol_escape_htmltag($from);
396 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTo').': '.dol_escape_htmltag($sendto));
397 if ($sendtocc) {
398 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".dol_escape_htmltag($sendtocc));
399 }
400 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
401 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
402 $actionmsg = dol_concatdesc($actionmsg, $message);
403 }*/
404 }
405
406 // Create form object
407 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
408 $formmail = new FormMail($db);
409 $formmail->trackid = $trackid; // $trackid must be defined
410
411 $attachedfiles = $formmail->get_attached_files();
412 $filepath = $attachedfiles['paths'];
413 $filename = $attachedfiles['names'];
414 $mimetype = $attachedfiles['mimes'];
415
416 // Make substitution in email content
417 $substitutionarray = getCommonSubstitutionArray($langs, 0, null, $object);
418
419 $substitutionarray['__SENDEREMAIL_SIGNATURE__'] = (empty($emailsendersignature) ? $user->signature : $emailsendersignature);
420 $substitutionarray['__EMAIL__'] = $sendto;
421 $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"/>' : '';
422
423 $parameters = array('mode' => 'formemail');
424 complete_substitutions_array($substitutionarray, $langs, $object, $parameters);
425
426 $subject = make_substitutions($subject, $substitutionarray);
427 $message = make_substitutions($message, $substitutionarray);
428
429 if (is_object($object) && method_exists($object, 'makeSubstitution')) {
430 $subject = $object->makeSubstitution($subject);
431 $message = $object->makeSubstitution($message);
432 }
433
434 // Send mail (substitutionarray must be done just before this)
435 if (empty($sendcontext)) {
436 $sendcontext = 'standard';
437 }
438 $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1, '', '', $trackid, '', $sendcontext, $replyto, $upload_dir_tmp);
439
440 if (!empty($mailfile->error) || !empty($mailfile->errors)) {
441 setEventMessages($mailfile->error, $mailfile->errors, 'errors');
442 $action = 'presend';
443 } else {
444 $result = $mailfile->sendfile();
445 if ($result) {
446 // Initialisation of datas of object to call trigger
447 if (is_object($object)) {
448 $db->begin(); // Transaction for post action must start after sending email to avoid lock when sending email that may be long
449
450 if (empty($actiontypecode)) {
451 $actiontypecode = 'AC_EMAIL'; // Event inserted into agenda automatically
452 }
453
454 $object->socid = $sendtosocid; // To link to a company
455 $object->sendtoid = $sendtoid; // To link to contact-addresses. This is an array.
456 $object->actiontypecode = $actiontypecode; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
457 $object->actionmsg = $message; // Long text
458 $object->actionmsg2 = $actionmsg2; // Short text ($langs->transnoentities('MailSentByTo')...);
459 if (getDolGlobalString('MAIN_MAIL_REPLACE_EVENT_TITLE_BY_EMAIL_SUBJECT')) {
460 $object->actionmsg2 = $subject; // Short text
461 }
462
463 $object->trackid = $trackid;
464 $object->fk_element = $object->id;
465 $object->elementtype = $object->element;
466 if (is_array($attachedfiles) && count($attachedfiles) > 0) {
467 $object->attachedfiles = $attachedfiles;
468 }
469 if (is_array($sendtouserid) && count($sendtouserid) > 0 && getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) {
470 $object->sendtouserid = $sendtouserid;
471 }
472
473 // TODO Fix this: Such properties does not exists on all objects
474 $object->context['email_msgid'] = $mailfile->msgid;
475 $object->context['email_from'] = $from;
476 $object->context['email_subject'] = $subject;
477 $object->context['email_to'] = $sendto;
478 $object->context['email_tocc'] = $sendtocc;
479 $object->context['email_tobcc'] = $sendtobcc;
480
481 $object->email_msgid = $mailfile->msgid; // @todo Set msgid into $mailfile after sending
482 $object->email_from = $from;
483 $object->email_subject = $subject;
484 $object->email_to = $sendto;
485 $object->email_tocc = $sendtocc;
486 $object->email_tobcc = $sendtobcc;
487
488 // Call of triggers (you should have set $triggersendname to execute trigger.
489 if (!empty($triggersendname)) {
490 if ($triggersendname == 'BILL_SENTBYMAIL' && $object instanceof Facture) {
491 /* @var Facture $object */
492
493 // If sending email for invoice, we increase the counter of invoices sent by email
494 $sql = "UPDATE ".MAIN_DB_PREFIX."facture SET email_sent_counter = email_sent_counter + 1";
495 $sql .= " WHERE rowid = ".((int) $object->id);
496
497 $resql = $db->query($sql);
498 if ($resql) {
499 $object->email_sent_counter += 1;
500 }
501 }
502
503 $result = $object->call_trigger($triggersendname, $user); // @phan-suppress-current-line PhanPossiblyUndeclaredGlobalVariable
504 if ($result < 0) {
505 $error++;
506 }
507 if ($error) {
508 setEventMessages($object->error, $object->errors, 'errors');
509 }
510 }
511 // End call of triggers
512
513 if (!$error) {
514 $db->commit();
515 } else {
516 $db->rollback();
517 }
518 }
519
520 // Redirect here
521 // This avoid sending mail twice if going out and then back to page
522 $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($sendto, 2));
523 setEventMessages($mesg, null, 'mesgs');
524
525 header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname ?? 'id').'='.(is_object($object) ? $object->id : ''));
526 exit;
527 } else {
528 $langs->load("other");
529 $mesg = '<div class="error">';
530 if (!empty($mailfile->error) || !empty($mailfile->errors)) {
531 $mesg .= $langs->transnoentities('ErrorFailedToSendMail', dol_escape_htmltag($from), dol_escape_htmltag($sendto));
532 if (!empty($mailfile->error)) {
533 $mesg .= '<br>'.$mailfile->error;
534 }
535 if (!empty($mailfile->errors) && is_array($mailfile->errors)) {
536 $mesg .= '<br>'.implode('<br>', $mailfile->errors);
537 }
538 } else {
539 $mesg .= $langs->transnoentities('ErrorFailedToSendMail', dol_escape_htmltag($from), dol_escape_htmltag($sendto));
540 if (getDolGlobalString('MAIN_DISABLE_ALL_MAILS')) {
541 $mesg .= '<br>Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
542 } else {
543 $mesg .= '<br>Unknown Error, please refer to your administrator';
544 }
545 }
546 $mesg .= '</div>';
547
548 setEventMessages($mesg, null, 'warnings');
549 $action = 'presend';
550 }
551 }
552 } else {
553 $langs->load("errors");
554 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("MailTo")), null, 'warnings');
555 dol_syslog('Try to send email with no recipient defined', LOG_WARNING);
556 $action = 'presend';
557 }
558 } else {
559 $langs->load("errors");
560 setEventMessages($langs->trans('ErrorFailedToReadObject', $object->element), null, 'errors');
561 dol_syslog('Failed to read data of object id='.$object->id.' element='.$object->element);
562 $action = 'presend';
563 }
564}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
global $dolibarr_main_url_root
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
Class to manage contact/addresses.
Class to manage invoices.
Class to manage a HTML form to send a unitary email Usage: $formail = new FormMail($db) $formmail->pr...
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_add_file_process($upload_dir, $allowoverwrite=0, $updatesessionordb=0, $keyforsourcefile='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1, $object=null, $forceFullTextIndexation='', $mode=0)
Get and save an upload file (for example after submitting a new file in a mail form).
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_remove_file_process($filenb, $donotupdatesession=0, $donotdeletefile=1, $trackid='')
Remove an uploaded file (for example after submitting a new file a mail form).
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.