Sugarcrm EmailFormatter $mailer->setHtmlBody($body) function not working when description field of task module contains formatted text without html tags.

Hi All,

SugarCRM $mailer->setHtmlBody($body) function not working when description field of task module contains formatted text without html tags.

Steps to reproduce:
1. Create Task record with description field value as below:
"Dear Sugar Administrator,

On XXX, XXX Xth 1555 , beginning Time, SugarCRM will be performing maintenance. Maintenance is expected to be complete.

Please note that this only affect you if you are using tXXX service."

2. Create email temaplte and add description field in template.

3. Try to send email using custom code as below:
"
try{
$oTemplate = new EmailTemplate();
$oMail = MailerFactory::getSystemDefaultMailer();
$mailTransmissionProtocol = $oMail->getMailTransmissionProtocol();
$oTemplate->retrieve_by_string_fields(array('name' => "Temaplate Name", 'type' => 'email'));
$oMail->clearRecipients();
$oMail->addRecipientsTo(new EmailIdentity("Test@email.com","Test User"));
$body = trim($oTemplate->body_html);
$oMail->setHtmlBody($body);
$oMail->Send()
}catch(MailerException $me) {
$message = $me->getMessage();
$GLOBALS["log"]->fatal(
"Send Email: error sending e-mail (method: {$mailTransmissionProtocol}), (error: {$message})"
);
}

"

4. check received email now:
"
Description :
Dear Sugar Administrator, On XXX, XXX Xth 1555 , beginning Time, SugarCRM will be performing maintenance. Maintenance is expected to be complete. Please note that this only affect you if you are using tXXX service.
"

But expected output was :
"Description :
Dear Sugar Administrator,

On XXX, XXX Xth 1555 , beginning Time, SugarCRM will be performing maintenance. Maintenance is expected to be complete.

Please note that this only affect you if you are using tXXX service.
"

Thanks,

Shreya

Parents
  •  ,

    Your "expected output" is not correct for the data you supplied. The input has been correctly marked up as HTML, exactly as you asked it to.

    HTML does not recognise whitespace as formatting and will convert any and all whitespace to a single space character. If you want to specify formatting for the output as HTML then you need to use HTML tags to do the formatting. That is what "Markup" means Slight smile

    Any text supplied without tags is simply treated as a single string of text characters, any multiple spaces, tabs, new lines etc. are all replaced by a single space.

    Try pasting your above input into a text editor, save it as a .html file and then view it in a web browser. You will likely get the same result as you see in the email received.

    Thanks,

    JH.

Reply
  •  ,

    Your "expected output" is not correct for the data you supplied. The input has been correctly marked up as HTML, exactly as you asked it to.

    HTML does not recognise whitespace as formatting and will convert any and all whitespace to a single space character. If you want to specify formatting for the output as HTML then you need to use HTML tags to do the formatting. That is what "Markup" means Slight smile

    Any text supplied without tags is simply treated as a single string of text characters, any multiple spaces, tabs, new lines etc. are all replaced by a single space.

    Try pasting your above input into a text editor, save it as a .html file and then view it in a web browser. You will likely get the same result as you see in the email received.

    Thanks,

    JH.

Children
No Data