-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
Bug
When from a ticket card (of Ticket module) we try to send an email (so, "add message" with the option "send message by email" checkmarked), and if we use the select box to choose an email template, then the email being sent doesn't use the "from" attribute of that email template.
@eldy I have solved it after two hours of inverse engineering to find why it was happening. The problem is at the file:
/htdocs/ticket/class/ticket.class.php (line #3064)The function sendTicketMessageByEmail() takes as sender this global value independently of the template:
$from = getDolGlobalString('TICKET_NOTIFICATION_EMAIL_FROM');Solution i've used:
- Add at the "sending mail" form on the ticket card a hidden INPUT with the email_from value of the choosen email template:
file: /core/class/html.formticket.class.php (line #1555)
where now there is this:
// From
$from = getDolGlobalString('TICKET_NOTIFICATION_EMAIL_FROM');
print '<tr class="email_line"><td><span class="">'.$langs->trans("MailFrom").'</span></td>';
print '<td><span class="">'.img_picto('', 'email', 'class="pictofixedwidth"').$from.'</span></td></tr>';I've put this other:
// From
$from = getDolGlobalString('TICKET_NOTIFICATION_EMAIL_FROM');
if (is_object($arraydefaultmessage) && $arraydefaultmessage->email_from
&& !empty($arraydefaultmessage->email_from)) {
$from = $arraydefaultmessage->email_from;
}
print '<tr class="email_line"><td><span class="">'.$langs->trans("MailFrom").'</span></td>';
print '<td><span class="">'.img_picto('', 'email', 'class="pictofixedwidth"').$from.'</span>'
.'<input type="hidden" name="email_from" value="'.$from.'" /></td></tr>';- then at the file
/htdocs/ticket/class/ticket.class.php (line #3064)instead of:
$from = getDolGlobalString('TICKET_NOTIFICATION_EMAIL_FROM');we can put this:
$from = GETPOST('email_from', 'alphanohtml') ? GETPOST('email_from', 'alphanohtml') : getDolGlobalString('TICKET_NOTIFICATION_EMAIL_FROM');in other words, we check if by $_POST we get a value for the variable email_from.
Conclusion
I have tested it and it runs well. In fact, it's quite simple: take the sender value of the email template when choosing it on the web form to send the email, and then take that value on the sendTicketMessageByEmail() function if it's not empty.
I suspect that sometime in the past someone introduced the possibility of set the "email from" attribute in the "email templates" (as a new Dolibarr feature) but because Ticket module is quite "special" then this feature was not being used there.
Dolibarr Version
20.X at least
Environment PHP
No response
Environment Database
No response
Steps to reproduce the behavior and expected behavior
Basically: you must send an email from an existing ticket using an specific email template which has defined as SENDER a customized email address.
Step by step:
- got to Setup / Emails / Email templates and define a new template with a different "send from" email address than the default one for dolibarr and for the ticket module
- open a new ticket where you were the "contact" who open the ticket, so you will receive the emails sent by the internal users
- visit that ticket as administrator or internal user
- click on "send email" button
- on the "email form" choose an "email template" and click "apply"
- after being reloaded the page, click on "add message"
- then the system will send an email FROM THE DEFAULT email address defined for the module, not from the FROM EMAIL address defined on the email template
Attached files
No response