How to parse description contains html tags while sending email to user programmatically

Hi,

How to parse description contains html tags while sending email to user programmatically?

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->ClearAllRecipients();
$oMail->ClearReplyTos();
$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;
$oMail->IsHTML(true);
$oMail->prepForOutbound();
$oMail->setMailerForSystem();

"

$task_description is variable in email template, so tried to replace using strip_tags($oTask->description) to parse html content, but

 not working as expected and $oTask->description contains data like : 

"Dear Sugar Administrator,<br /> On XXX, XXX Xth 1555 , beginning  Time, SugarCRM will be performing maintenance. Maintenance is expected to be complete.<br /> Please note that this only affect you if you are using tXXX  service.<br /> "

Current Output - 

"Dear Sugar Administrator,On XXXXXX 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."

Expected output -

"Dear Sugar Administrator,

On XXXXXX 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
  • Hi,

    You can use the SugarMailer class to send emails programmatically in SugarCRM. The SugarMailer class allows you to set the HTML version of the email body, which can contain HTML tags. You can use the setHtml() method to set the HTML version of the email body, have a look below:

    $mailer = new SugarMailer();

    $mailer->setHtml($emailBody);

    $mailer->send();

    You can then use a HTML parser library to parse the HTML tags in the email body before setting it as the HTML version of the email body.

    Bruce McIntyre

Reply
  • Hi,

    You can use the SugarMailer class to send emails programmatically in SugarCRM. The SugarMailer class allows you to set the HTML version of the email body, which can contain HTML tags. You can use the setHtml() method to set the HTML version of the email body, have a look below:

    $mailer = new SugarMailer();

    $mailer->setHtml($emailBody);

    $mailer->send();

    You can then use a HTML parser library to parse the HTML tags in the email body before setting it as the HTML version of the email body.

    Bruce McIntyre

Children
No Data