Skip to content

SENDER email address of the email template is note being used by TICKET module when sending an email message from a ticket [EASY SOLUTION PROPOSED AND TESTED] #31999

@caos30

Description

@caos30

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:

  1. 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>';
  1. 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:

  1. 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
  2. open a new ticket where you were the "contact" who open the ticket, so you will receive the emails sent by the internal users
  3. visit that ticket as administrator or internal user
  4. click on "send email" button
  5. on the "email form" choose an "email template" and click "apply"
  6. after being reloaded the page, click on "add message"
  7. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis is a bug (something does not work as expected)Issue Stale (automatic label)This issue is stale because it has been open 1 year with no activity. Remove this label to keep open

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions