Sugar 11.0.2: Email to case causes formatting to be incorrect


An onpremise customer of ours got updated from 9.0.2 to 11.0.2 recently. One of the key features they use is the capability of importing e-mails and creating a case from it. We noticed a difference in how Sugar used to handle the creation of the case and how it is working since the upgrade. 

When we open the e-mail the body of the mail (description_html) seems to be fine and looks ok. When we open the created case on the other hand all seems to be scrambled and the HTML is not correctly converted as how it was in 9.0.2. The HTML contains a lot of tables. (it is a form submission converted to a table like structure to show it correctly in e-mail). As said, in the email it looks al correct because HTML is disabled. 

Did anyone notice this behaviour as well and if so how can we fix it? We already thought about a temporary solution by adding a description_html field in the cases module and copy the html from the email to the case when it is created and show the description / description_html field based on a checkbox. But that has its drawbacks also. 

  • I have had issues with html encoding in the Case description since v7.0 and it keeps coming back like a bad penny...

    The latest recurrence was Defect #(81812) which was fixed in 11.3  which, of course, is not available OnSite. 
    I asked for a hot fix but they could not give me one, and told me to wait for the upgrade to v12. 

    I've not upgraded to v12 yet for a series of reasons, not the least of which is I have to convert to Enterprise first and review all the customizations I did to add the features that Enterprise now has out of the box...

    I hope your customer's transition to v12 is easier than mine :)

  • Thanks for the answer. Do you know or encountered any issues when converting the html and newlines are being broken in the past?

    For instance the issue we are currently facing is with the following text (without "):
    "Test Person"

    gets translated in the case to:

  • I have not had that complaint from our people, but they are so used to the Case description being mangled that they may not have mentioned it.

  • I just implemented a *fix* for this. I created a textarea, converted it to html ( using vardefs) and added a logic hook that in certain circumstances copies the description_html from the email to the case. On the case we show the description_html field depending on its value. Seems to work and shows the case data correctly

  • Dear Francesca,

    I am facing issue that my description contains formatted html data and while sending email to user programmatically,

    description field not formatted.

    My code:


    $oTemplate = new EmailTemplate();
    $oMail = new SugarPHPMailer();
    $oEmailObj = new Email();
    $oTemplate->retrieve_by_string_fields(array('name' => "Template Name", 'type' => 'email'));
    $defaults = $oEmailObj->getSystemDefaultEmail();
    $oMail->From = $defaults['email'];
    $oMail->FromName = $defaults['name'];
    $oMail->AddAddress($oUser->email1, $oUser->full_name);
    $test = $oUser->full_name;
    $oMail->Subject = parse_alert_template($oTask, $oTemplate->subject);
    $body = parse_alert_template($oTask, $oTemplate->body_html);
    $description = strip_tags($oTask->description);
    $body = str_replace('$task_description',$description,$body);
    $oMail->Body_html = from_html($body);
    $oMail->Body = wordwrap($body, 900);
    $oMail->Body = $body;


    but this was working previously.

    Your help is appreciated.



  • I use Mailer Factory to send emails, I think it's better than using the Email bean directly.

    I built a small utility function that I reuse in various parts of my code and it seems to work fine. The $EmailBody is strictly HTML in my case.

    Per the manual you can set the Text Body and/or the HTML body:

    $mailer->setTextBody("This is a text body message");
    // HTML Body
    $mailer->setHtmlBody("This is an <b>HTML</b> body message. <br> You can use html tags.");

    This is my Utility function, which can probably be improved (I wrote it several years ago), but it still works on the v11, I have not tested it in v12 yet but see no reason it should stop working, at least for now.

      //Function to send Email message
      //one email per recipient
    function sendEmail($ToEmailAdd, $FromEmailAdd, $FromEmailName, $EmailSubject, $EmailBody) {
      global $sugar_config;
      require_once ('modules/Emails/Email.php');
        $To = $ToEmailAdd;
        $To = explode(';',$ToEmailAdd);
      foreach ($To as $to_addr){
        if (filter_var($to_addr, FILTER_VALIDATE_EMAIL)){
            $phpMailer = MailerFactory::getSystemDefaultMailer();
            $mailTransmissionProtocol = $phpMailer->getMailTransmissionProtocol();
            $FromEmailIdentity = new EmailIdentity($FromEmailAdd, $FromEmailName);
            $header_array = array(
              'Sender'=>$FromEmailIdentity, //mandatory
            $phpMailer->addRecipientsTo(new EmailIdentity($to_addr, $to_addr));
          }catch(MailerException $me) {
            $message = $me->getMessage();
              "SendEmail: error sending e-mail (method: {$mailTransmissionProtocol}), (error: {$message})"
          $message = 'BAD EMAIL ADDRESS To: ' . $to_addr;