<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://sugarclub.sugarcrm.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Sugar 11.0.2: Email to case causes formatting to be incorrect</title><link>https://sugarclub.sugarcrm.com/dev-club/f/questions-answers/5705/sugar-11-0-2-email-to-case-causes-formatting-to-be-incorrect</link><description>Hi, 
 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</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Sugar 11.0.2: Email to case causes formatting to be incorrect</title><link>https://sugarclub.sugarcrm.com/thread/27999?ContentTypeID=1</link><pubDate>Tue, 10 Jan 2023 13:57:37 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:8cb25bb8-2afc-4289-9008-f2c779a1eacb</guid><dc:creator>Francesca Shiekh</dc:creator><description>&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;I use Mailer Factory to send emails, I think it&amp;#39;s better than using the Email bean directly.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_12.0/Architecture/Email/Mailer_Factory/"&gt;support.sugarcrm.com/.../&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;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.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Per the manual you can set the Text Body and/or the HTML body:&lt;/span&gt;&lt;/p&gt;
&lt;pre class="line-numbers  language-php"&gt;&lt;code class=" language-php"&gt;&lt;span class="token variable"&gt;$mailer&lt;/span&gt;&lt;span class="token operator"&gt;-&lt;/span&gt;&lt;span class="token operator"&gt;&amp;gt;&lt;/span&gt;&lt;span class="token function"&gt;setTextBody&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token double-quoted-string string"&gt;&amp;quot;This is a text body message&amp;quot;&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;

&lt;span class="token comment"&gt;// HTML Body&lt;/span&gt;
&lt;span class="token variable"&gt;$mailer&lt;/span&gt;&lt;span class="token operator"&gt;-&lt;/span&gt;&lt;span class="token operator"&gt;&amp;gt;&lt;/span&gt;&lt;span class="token function"&gt;setHtmlBody&lt;/span&gt;&lt;span class="token punctuation"&gt;(&lt;/span&gt;&lt;span class="token double-quoted-string string"&gt;&amp;quot;This is an &amp;lt;b&amp;gt;HTML&amp;lt;/b&amp;gt; body message. &amp;lt;br&amp;gt; You can use html tags.&amp;quot;&lt;/span&gt;&lt;span class="token punctuation"&gt;)&lt;/span&gt;&lt;span class="token punctuation"&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This is my Utility function, which can probably be improved (I wrote it&amp;nbsp;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.&lt;br /&gt;&lt;pre class="ui-code" data-mode="php"&gt;&amp;lt;?php
  //Function to send Email message
  //one email per recipient

function sendEmail($ToEmailAdd, $FromEmailAdd, $FromEmailName, $EmailSubject, $EmailBody) {
  global $sugar_config;
  require_once (&amp;#39;modules/Emails/Email.php&amp;#39;);
  if(is_array($ToEmailAdd)){
    $To = $ToEmailAdd;
  }else{
    $To = explode(&amp;#39;;&amp;#39;,$ToEmailAdd);
  }
  foreach ($To as $to_addr){
    if (filter_var($to_addr, FILTER_VALIDATE_EMAIL)){
      try{
        $phpMailer = MailerFactory::getSystemDefaultMailer();
        $mailTransmissionProtocol = $phpMailer-&amp;gt;getMailTransmissionProtocol();
        $FromEmailIdentity = new EmailIdentity($FromEmailAdd, $FromEmailName);
        $header_array = array(
          &amp;#39;From&amp;#39;=&amp;gt;$FromEmailIdentity,
          &amp;#39;ReplyTo&amp;#39;=&amp;gt;&amp;#39;&amp;#39;,
          &amp;#39;Sender&amp;#39;=&amp;gt;$FromEmailIdentity, //mandatory
          &amp;#39;Subject&amp;#39;=&amp;gt;$EmailSubject,
        );
        $phpMailer-&amp;gt;constructHeaders($header_array);
        $phpMailer-&amp;gt;addRecipientsTo(new EmailIdentity($to_addr, $to_addr));
        $phpMailer-&amp;gt;setHtmlBody($EmailBody);
        $phpMailer-&amp;gt;send();
      }catch(MailerException $me) {
        $message = $me-&amp;gt;getMessage();
        $GLOBALS[&amp;quot;log&amp;quot;]-&amp;gt;fatal(
          &amp;quot;SendEmail: error sending e-mail (method: {$mailTransmissionProtocol}), (error: {$message})&amp;quot;
        );
        return($message);
      }
    }else{
      $message = &amp;#39;BAD EMAIL ADDRESS To: &amp;#39; . $to_addr;
      return($message);
    }
  }
  return;
}
?&amp;gt;
&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Francesca&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sugar 11.0.2: Email to case causes formatting to be incorrect</title><link>https://sugarclub.sugarcrm.com/thread/27995?ContentTypeID=1</link><pubDate>Tue, 10 Jan 2023 09:02:01 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:42bd800f-857d-4a82-b12e-4dc078c3bd8d</guid><dc:creator>shreya dalvi</dc:creator><description>&lt;p&gt;Dear Francesca,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I am facing issue that my description contains formatted html data and while sending email to user programmatically,&lt;/p&gt;
&lt;p&gt;description field not formatted.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;My code:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;quot;&lt;/p&gt;
&lt;p&gt;$oTemplate = new EmailTemplate();&lt;br /&gt;$oMail = new SugarPHPMailer();&lt;br /&gt;$oEmailObj = new Email();&lt;br /&gt;$oTemplate-&amp;gt;retrieve_by_string_fields(array(&amp;#39;name&amp;#39; =&amp;gt; &amp;quot;Template Name&amp;quot;, &amp;#39;type&amp;#39; =&amp;gt; &amp;#39;email&amp;#39;));&lt;br /&gt;$defaults = $oEmailObj-&amp;gt;getSystemDefaultEmail();&lt;br /&gt;$oMail-&amp;gt;From = $defaults['email'];&lt;br /&gt;$oMail-&amp;gt;FromName = $defaults['name'];&lt;br /&gt;$oMail-&amp;gt;ClearAllRecipients();&lt;br /&gt;$oMail-&amp;gt;ClearReplyTos();&lt;br /&gt;$oMail-&amp;gt;AddAddress($oUser-&amp;gt;email1, $oUser-&amp;gt;full_name);&lt;br /&gt;$test = $oUser-&amp;gt;full_name;&lt;br /&gt;$oMail-&amp;gt;Subject = parse_alert_template($oTask, $oTemplate-&amp;gt;subject);&lt;br /&gt;$body = parse_alert_template($oTask, $oTemplate-&amp;gt;body_html);&lt;br /&gt;&lt;strong&gt;$description = strip_tags($oTask-&amp;gt;description);&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;$body = str_replace(&amp;#39;$task_description&amp;#39;,$description,$body);&lt;/strong&gt;&lt;br /&gt;$oMail-&amp;gt;Body_html = from_html($body);&lt;br /&gt;$oMail-&amp;gt;Body = wordwrap($body, 900);&lt;br /&gt;$oMail-&amp;gt;Body = $body;&lt;br /&gt;$oMail-&amp;gt;IsHTML(true);&lt;br /&gt;$oMail-&amp;gt;prepForOutbound();&lt;br /&gt;$oMail-&amp;gt;setMailerForSystem();&lt;/p&gt;
&lt;p&gt;&amp;quot;&lt;/p&gt;
&lt;p&gt;but this was working previously.&lt;/p&gt;
&lt;p&gt;Your help is appreciated.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Shreya&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sugar 11.0.2: Email to case causes formatting to be incorrect</title><link>https://sugarclub.sugarcrm.com/thread/26806?ContentTypeID=1</link><pubDate>Mon, 20 Jun 2022 08:48:11 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:bf175ed2-d1eb-4fd9-93dd-0b54c445c934</guid><dc:creator>Jeroen Somhorst</dc:creator><description>&lt;p&gt;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&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sugar 11.0.2: Email to case causes formatting to be incorrect</title><link>https://sugarclub.sugarcrm.com/thread/26794?ContentTypeID=1</link><pubDate>Fri, 17 Jun 2022 13:46:24 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:f68b0ce2-6bc9-400d-86cb-d2ecdf7b19af</guid><dc:creator>Francesca Shiekh</dc:creator><description>&lt;p&gt;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.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sugar 11.0.2: Email to case causes formatting to be incorrect</title><link>https://sugarclub.sugarcrm.com/thread/26789?ContentTypeID=1</link><pubDate>Thu, 16 Jun 2022 14:07:34 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:f72f60e6-f17b-49b3-8f13-b1b597ee04e5</guid><dc:creator>Jeroen Somhorst</dc:creator><description>&lt;p&gt;Thanks for the answer. Do you know or encountered any issues when converting the html and newlines are being broken in the past?&lt;/p&gt;
&lt;p&gt;For instance the issue we are currently facing is with the following text (without &amp;quot;):&lt;br /&gt;&amp;quot;Test Person&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;gets translated in the case to:&lt;br /&gt;&amp;quot;Test&amp;nbsp;&lt;br /&gt;Person&amp;quot;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sugar 11.0.2: Email to case causes formatting to be incorrect</title><link>https://sugarclub.sugarcrm.com/thread/26788?ContentTypeID=1</link><pubDate>Thu, 16 Jun 2022 13:44:42 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:57e4d8be-3077-4adf-a54a-901fdd916f3c</guid><dc:creator>Francesca Shiekh</dc:creator><description>&lt;p&gt;I have had issues with html encoding in the Case description since v7.0 and it keeps coming back like a bad penny...&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The latest&amp;nbsp;recurrence was&amp;nbsp;Defect #(81812) which was fixed in 11.3&amp;nbsp; which, of course, is not available OnSite.&amp;nbsp;&lt;br /&gt;I asked for a hot fix but they could not give me one, and told me to wait for the upgrade to v12.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I&amp;#39;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...&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I hope your customer&amp;#39;s transition to v12 is easier than mine :)&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>