Dolibarr / dolibarr

Dolibarr ERP CRM is a modern software package to manage your company or foundation's activity (contacts, suppliers, invoices, orders, stocks, agenda, accounting, ...). it's an open source Web application (written in PHP) designed for businesses of any sizes, foundations and freelancers.
https://www.dolibarr.org
GNU General Public License v3.0
5.51k stars 2.8k forks source link

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

Open caos30 opened 1 week ago

caos30 commented 1 week ago

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

eldy commented 4 days ago

This is the expected behaviour to have all emails sent from the ticket interface to be sent with the from defined into TICKET_NOTIFICATION_EMAIL_FROM. The from should not come from the user form, for security and technical purpose (sending email should come from a email that is technically allowed). This is the goal of this option to set the from that is allowed to send email for ticket notification.

It's right that the email_from in templates were introduced for writing emails, not for ticket notification.

But i understand we may want to have the nale of sender for some messages. In such cases, sender email should be in reply-to. But this should be another option not yet available.