diff --git a/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php b/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php index 13d6676a8e3..dfd83022393 100644 --- a/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php +++ b/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php @@ -280,9 +280,11 @@ class InterfaceTicketEmail extends DolibarrTriggers dol_syslog($mailfile->error, LOG_DEBUG); } else { $result = $mailfile->sendfile(); - // update last_msg_sent date - $object->date_last_msg_sent = dol_now(); - $object->update($user); + if ($result) { + // update last_msg_sent date + $object->date_last_msg_sent = dol_now(); + $object->update($user); + } } if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index f246fb546c3..14c1e0719a3 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -2756,13 +2756,14 @@ class Ticket extends CommonObject // altairis: dont try to send email when no recipient if (!empty($sendto)) { - $this->sendTicketMessageByEmail($subject, $message, '', $sendto, $listofpaths, $listofmimes, $listofnames); + $result = $this->sendTicketMessageByEmail($subject, $message, '', $sendto, $listofpaths, $listofmimes, $listofnames); + if ($result) { + // update last_msg_sent date + $object->date_last_msg_sent = dol_now(); + $object->update($user); + } } } - - // update last_msg_sent date - $object->date_last_msg_sent = dol_now(); - $object->update($user); } } } @@ -2793,7 +2794,7 @@ class Ticket extends CommonObject * @param array $filename_list List of files to attach (full path of filename on file system) * @param array $mimetype_list List of MIME type of attached files * @param array $mimefilename_list List of attached file name in message - * @return void + * @return boolean True if mail sent to at least one receiver, false otherwise */ public function sendTicketMessageByEmail($subject, $message, $send_internal_cc = 0, $array_receiver = array(), $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array()) { @@ -2801,7 +2802,7 @@ class Ticket extends CommonObject if ($conf->global->TICKET_DISABLE_ALL_MAILS) { dol_syslog(get_class($this).'::sendTicketMessageByEmail: Emails are disable into ticket setup by option TICKET_DISABLE_ALL_MAILS', LOG_WARNING); - return ''; + return false; } $langs->load("mails"); @@ -2820,6 +2821,7 @@ class Ticket extends CommonObject } $from = $conf->global->TICKET_NOTIFICATION_EMAIL_FROM; + $is_sent = false; if (is_array($array_receiver) && count($array_receiver) > 0) { foreach ($array_receiver as $key => $receiver) { $deliveryreceipt = 0; @@ -2841,6 +2843,7 @@ class Ticket extends CommonObject $result = $mailfile->sendfile(); if ($result) { setEventMessages($langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($receiver, 2)), null, 'mesgs'); + $is_sent = true; } else { $langs->load("other"); if ($mailfile->error) { @@ -2859,6 +2862,7 @@ class Ticket extends CommonObject $langs->load("other"); setEventMessages($langs->trans('ErrorMailRecipientIsEmptyForSendTicketMessage'), null, 'warnings'); } + return $is_sent; } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps