Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

osTicket v1.10 (stable) and Maintenance Release v1.9.15 are now available! Go get it now

[mod] HTML Email Templates

This mod adds a field called HTML Email Template to the Preferences screen. In this field, you can enter an HTML template that will be used for every outgoing email. Insert a %message placeholder where you want the text of the outgoing message to be inserted into the template. If the script finds the %message placeholder in this field, it will automatically create an HTML MIME part in every outgoing email, in addition to the existing text part.

The mod required changes to:

* class.email.php
* class.config.php
* preferences.inc.php

The modified versions of those files are attached. This will work as a drop-in replacement for the original files with version 1.6ST. Additionally, you will have to add a new field, "html_email_template", in the ost_config database table. The field type should be "text". All the changes are commented with my initials, BSK.

This mod also fixes a bug in class.config.php that was causing the "Allow Spoof" setting to become disabled every time the Preferences screen was saved, regardless of whether the checkbox was enabled or disabled. This is completely unrelated to HTML templates, but since it fixes a fairly nasty bug, I figured I may as well include it.
«13

Comments

  • This MOD is only for the HTML Templates or it actually add the capability for OS Ticket to send Email in HTML?
  • mig2000;22789 said:
    This MOD is only for the HTML Templates or it actually add the capability for OS Ticket to send Email in HTML?
    Not sure I understand your question. With this mod, osTicket will send all emails with both a plain text part and an HTML part. The mod creates the HTML part by wrapping an HTML template that you define around your plain text message that you would type in a support ticket, etc...

    If you're asking whether you can use HTML within the actual message text, currently the answer would be no, because the HTML you enter would be sent in the plain text part of the email, which would make it unreadable for the 0.1% of people who still use plain text email programs.

    On the other hand, it's pretty easy to update the mod to support HTML within the message text. On line 171 of my modified class.email.php, change:

    $mime->setTXTBody($body);

    to

    $mime->setTXTBody(strip_tags($body));

    Now, your HTML part will be sent as HTML and your text part will be stripped of all the HTML tags, so it will be sent as plain text.
  • This worked great. Thanks for this mod!
  • i get an error response that ends with:



    Unknown column 'html_email_template' in 'field list'
  • guiloc4;23570 said:
    i get an error response that ends with:

    Unknown column 'html_email_template' in 'field list'
    That's correct. As I stated in my original post:

    Additionally, you will have to add a new field, "html_email_template", in the ost_config database table. The field type should be "text".
  • This MOD also allow to receive mail in html with image ?
    i have a problem when the client open a ticket via e-mail and attach an immage (screen shot) in the test to explain his problem.
    In this case in the ticket the image is lost.

    thanks
  • Paolo Poma;23813 said:
    This MOD also allow to receive mail in html with image ?
    i have a problem when the client open a ticket via e-mail and attach an immage (screen shot) in the test to explain his problem.
    In this case in the ticket the image is lost.

    thanks
    Sorry, but this mod has nothing to do with receiving emails. It affects sending only.
  • Help

    How can I add new field?
    What type command in mysql?
  • Most Excellent ;)

    Excellent piece of code. Thank You very much.;) I think we can all agree that the original format was a bit plain without any formatting. Your instructions were well worded and worked perfect right out of the box. Fortunatly, for me, the three files you .zipped we some of the few that I had not already made other changes to... but...

    There is always one of those in there...:D And this is not a bad thing, just a matter of conveneince for the person receiving the mail. I know the variables used in the orignal templates can not be used in the HTML box. The thing is, the link back to the support system to check/update your ticket info "was" an html link that could just be clicked on in the email. With the HTML format around it, it is no longer a link, but just text. This software is too new for me to figure it out, so I was wondering if anyone had found a way around that so clickable links could be put into the original templates, or code to find and convert links to a clickable link before it is sent. Thanks Bkonia !!!
  • I change this code from TXT to HTML and i'm still not getting html in my $message any suggestions?

            $mime->setHTMLBody($body);
  • Hi, I am having an "Internal Error". Does anyone know why? Everytime I type something in the "HTML Email Template" I get this error, not only HTML code... but if I simply type "%message" I get the error too.

    I would really appreciate if someone could help me out. :)
  • Paolo Poma;23813 said:
    This MOD also allow to receive mail in html with image ?
    i have a problem when the client open a ticket via e-mail and attach an immage (screen shot) in the test to explain his problem.
    In this case in the ticket the image is lost.

    thanks
    osTicket the screen shot or screendump feature does not work when a ticket is sent in, so if a user is emailing in and they paste a screenshot into the email, it does not get sent with the ticket. Amending a couple of files will allow them to start working:

    pipe.php

    Find:
    if($filename && $cfg->canUploadFileType($filename)) {
    $ticket->saveAttachment($filename,$part->body,$msgid,'M');
    }

    Just after add:
    //Allow embedded images from Outlook
    } elseif (!($part->disposition)
    && (!strcasecmp($part->ctype_primary,'image')) ) {
    $filename=$part->ctype_parameters['name'];
    if($filename && $cfg->canUploadFileType($filename)) {
    $ticket->saveAttachment($filename,$part->body,$msgid,'M');
    }

    class.mailfetch.php

    Find:

    function saveAttachments($ticket,$mid,$part,$index=0) {
    global $cfg;
    if($part && $part->ifdparameters && ($filename=$part->dparameters[0]->value)){ //attachment
    $index=$index?$index:1;
    if($ticket && $cfg->canUploadFileType($filename) && $cfg->getMaxFileSize()>=$part->bytes) {
    //extract the attachments...and do the magic.
    $data=$this->decode($part->encoding, imap_fetchbody($this->mbox,$mid,$index));
    $ticket->saveAttachment($filename,$data,$ticket->getLastMsgId(),'M');
    return;
    }
    //TODO: Log failure??
    }
    //Recursive attachment search!
    if($part && $part->parts) {
    foreach($part->parts as $k=>$struct) {
    if($index) $prefix = $index.'.';
    $this->saveAttachments($ticket,$mid,$struct,$prefix.($k+1));
    }
    }

    }


    Replace it with:

    function saveAttachments($ticket,$mid,$part,$index=0) {
    global $cfg;
    // Default disposition attachments
    if($part && $part->ifdparameters && ($filename=$part->dparameters[0]->value)){ //attachment
    $index=$index?$index:1;
    if($ticket && $cfg->canUploadFileType($filename) && $cfg->getMaxFileSize()>=$part->bytes) {
    //extract the attachments...and do the magic.
    $data=$this->decode($part->encoding, imap_fetchbody($this->mbox,$mid,$index));
    $ticket->saveAttachment($filename,$data,$ticket->getLastMsgId(),'M');
    return;
    }
    //TODO: Log failure??
    }
    // Bugfix elseif ($part && $part->ifparameters && $part->type == 5 && $part->encoding == 3) {
    $filename = 'Attachment_'.$index;
    // Attachment name
    foreach ($part->parameters as $parameter) {
    if (strtoupper($parameter->attribute) == 'NAME') {
    $filename = $parameter->value;
    }
    }
    // Change
    $data = $this->decode($part->encoding, imap_fetchbody($this->mbox,$mid,$index));
    $ticket->saveAttachment($filename,$data,$ticket->getLastMsgId(),'M');
    return;
    }
    //Recursive attachment search!
    if($part && $part->parts) {
    foreach($part->parts as $k=>$struct) {
    if($index) $prefix = $index.'.';
    $this->saveAttachments($ticket,$mid,$struct,$prefix.($k+1));
    }
    }
    }
  • Thank for a lot for this modification. Worked liked a charm!
  • bkonia;23571 said:
    That's correct. As I stated in my original post:

    Additionally, you will have to add a new field, "html_email_template", in the ost_config database table. The field type should be "text".
    Open up phpMyAdmin and run the following command against your config table. Edit ost_config with the name of the actual table if needed.

    ALTER TABLE `config` ADD `html_email_template` TEXT NULL DEFAULT NULL
    EDITED: With better code. If you have a prefix in your table name, be sure to edit it in front of config.
  • This is a beautiful mod. Thank you.
  • Great work on this. I just have one issue when this is implemented.

    On Emails that have the ability to be "replied" on, all of the HTML code up to the --Do Not Reply-- or whatever custom separator is used, gets pulled into the post.

    Do you have a method you are using to deal with this? One method would be to add --Do Not Edit-- to the HTML Template, and delete all the writes of the separator in class.ticket.php.. But that would make it look like you can reply to all messages, and not as clean.
  • bkonia;22756 said:
    This mod adds a field called HTML Email Template to the Preferences screen. In this field, you can enter an HTML template that will be used for every outgoing email. Insert a %message placeholder where you want the text of the outgoing message to be inserted into the template. If the script finds the %message placeholder in this field, it will automatically create an HTML MIME part in every outgoing email, in addition to the existing text part.

    The mod required changes to:

    * class.email.php
    * class.config.php
    * preferences.inc.php

    The modified versions of those files are attached. This will work as a drop-in replacement for the original files with version 1.6ST. Additionally, you will have to add a new field, "html_email_template", in the ost_config database table. The field type should be "text". All the changes are commented with my initials, BSK.

    This mod also fixes a bug in class.config.php that was causing the "Allow Spoof" setting to become disabled every time the Preferences screen was saved, regardless of whether the checkbox was enabled or disabled. This is completely unrelated to HTML templates, but since it fixes a fairly nasty bug, I figured I may as well include it.



    Thanks for the patch
  • Does someone can provide an example of html email template ?
    Perhaps I have done a mistake, because it doesn't work for me.
  • Doesnt allow me to add the table in phpmyadmin
  • stefkiller;25461 said:
    Does someone can provide an example of html email template ?
    Perhaps I have done a mistake, because it doesn't work for me.
    This worked well for me.




    TD{font-family: Arial; font-size: 10pt;}
    table { width: 700px; border: table-layout: fixed; }











    image
     
    %message



    This is a basic table structure to control width and centering. It also includes a logo at the top which I substituted the google logo for.

    Also notice the use of the "%message" as written in the instructions. This is working well, the only issue I'm having is a broader issue with the multi-part headers being properly recognized. I'm working with the headers now to see if a change is needed to get the emails to show up properly in an outlook. Google mail works, but other web based email clients don't seem to be consistent.

    -Robert
  • bkonia - thank you for sharing! One small tweak :-)

    I download the code, applied the described changes and it was working great with some web based email clients like google mail, but I couldn't seem to get it working with outlook mail clients.

    After some trial and error, I realized the Mime_mail() object needed to be initialized with the newline string.

    Change line #170 of bkonia's patched "class.email.php"

    old code: $mime = new Mail_mime();
    new code: $mime = new Mail_mime($eol);

    This corrected the problem where my new HTML emails were coming in as unidentifiable text and attachments to outlook. After I changed the code to instantiate $mime with the newline character, it worked great.

    I'm not sure if PEAR assumes a winows or the osTicket deployment does, but this was required for me on centos.

    -Robert
  • Unable to find HTML in preferences

    Dear All,

    I have made the changes to my OSTicket, after following the steps, I am not able to find any section with name HTML in my preferences. appreciate your help on this.

    Thanks and Best Regards,

    :rolleyes:
  • hi fellas,

    I applied the mod, created the table field, but whenever i paste something in the html template field and i push save, it says it was successful, but whenever I return, that field is empty, there's no trace of my template in the emails, and the sql field in mysql stays NULL.

    what am I doing wrong ? :-/
  • odekmin;26620 said:
    hi fellas,

    I applied the mod, created the table field, but whenever i paste something in the html template field and i push save, it says it was successful, but whenever I return, that field is empty, there's no trace of my template in the emails, and the sql field in mysql stays NULL.

    what am I doing wrong ? :-/
    Got it, a php wiz pointed to me that I had copied the files in the wrong folder, instead of .

    cheers,
  • Hello,

    Is it possible to put a picture of my entreprise in an email template ?

    Is the client will view this picture ?

    Thank you in advance.
  • Very nice mod!!

    It works like a charm.

    Thanks & congrats!!
  • AlphaDesignsGroup;23865 said:

    There is always one of those in there...:D And this is not a bad thing, just a matter of conveneince for the person receiving the mail. I know the variables used in the orignal templates can not be used in the HTML box. The thing is, the link back to the support system to check/update your ticket info "was" an html link that could just be clicked on in the email. With the HTML format around it, it is no longer a link, but just text. This software is too new for me to figure it out, so I was wondering if anyone had found a way around that so clickable links could be put into the original templates, or code to find and convert links to a clickable link before it is sent. Thanks Bkonia !!!
    Has anyone solved this annoying problem? ;)
  • Lupo76;27448 said:
    Has anyone solved this annoying problem? ;)
    I answered myself :-)
    Unfortunately it was not easy because I have no knowledge of PHP:

    the solution is as follows:
    look in the file class.email.php the following code:


    $subject=stripslashes(preg_replace(\"/(\r\n|\r|\n)/s\",'', trim($subject)));
    $body = stripslashes(preg_replace(\"/(\r\n|\r)/s\", \"\n\", trim($message)));


    added below the last line of code shown above as follows:


    //Inizio codice per convertire url in link
    $trova = \"((http://|ftp://)[a-zA-Z0-9-_.]+[a-zA-Z0-9/.?&=_@]+)\";
    $nuovo = \"<a href=\\"$0\\" target=\\"_blank\\"> $0 </a>\";
    $body = preg_replace($trova, $nuovo, $body);
    //Fine codice per convertire url in link


    Hello
  • Never Mind - Great Mod!
  • Email Content Problem
    bkonia;22756 said:
    This mod adds a field called HTML Email Template to the Preferences screen. In this field, you can enter an HTML template that will be used for every outgoing email. Insert a %message placeholder where you want the text of the outgoing message to be inserted into the template. If the script finds the %message placeholder in this field, it will automatically create an HTML MIME part in every outgoing email, in addition to the existing text part.

    The mod required changes to:

    * class.email.php
    * class.config.php
    * preferences.inc.php

    The modified versions of those files are attached. This will work as a drop-in replacement for the original files with version 1.6ST. Additionally, you will have to add a new field, "html_email_template", in the ost_config database table. The field type should be "text". All the changes are commented with my initials, BSK.

    This mod also fixes a bug in class.config.php that was causing the "Allow Spoof" setting to become disabled every time the Preferences screen was saved, regardless of whether the checkbox was enabled or disabled. This is completely unrelated to HTML templates, but since it fixes a fairly nasty bug, I figured I may as well include it.
    Hi,

    Thanks for your efforts to put in an HTML email code changes / plugin. I have tried with your plugin. Its works but with an annoying problem as mentioned ahead in the post. When any action is taken related to ticket an email is sent but the content is sent in loop means same content is nested with itself almost 5-6 times. Not able to identify the problem after so much of code review. Please help.....
    Thanks.....
Sign In or Register to comment.