AnsweredAssumed Answered

logic hook, email body stripped

Question asked by Francesca Shiekh on Sep 26, 2016
Latest reply on Sep 26, 2016 by Francesca Shiekh

I noticed that in 7.6.2.2 when I send an email with html tags the email body is stripped.

I use the following function to send emails from logic hooks:

 

<?php
  //Function to send Email message

  function sendEmail($ToEmailAdd, $FromEmailAdd, $FromEmailName, $EmailSubject, $EmailBody) {
    global $sugar_config;
    $GLOBALS['log']->debug('PREPARE EMAIL to ' . print_r($ToEmailAdd, true));
    require_once ('modules/Emails/Email.php');
    if(is_array($ToEmailAdd)){
      $To = $ToEmailAdd;
    }else{
      $To = explode(';',$ToEmailAdd);
    }
    $now = gmdate("Y-m-d H:i:s");
    foreach ($To as $to_addr){
       $GLOBALS['log']->debug('PREPARE EMAIL TO:' . $to_addr);
       if (filter_var($to_addr, FILTER_VALIDATE_EMAIL)){
                $email = new Email();
                $email->to_addrs_arr = array(array('email' => $to_addr));
                $email->to_addrs = $to_addr;
                $email->from_addr = $FromEmailAdd;
                $email->from_name = $FromEmailName;
                //empty values are necessary to avoid undefined errors in Email.php
                $email->cc_addrs_arr = array();
                $email->bcc_addrs_arr = array();
                $email->saved_attachments = array();
                $email->name = $EmailSubject;
                $email->description_html = $EmailBody;
$GLOBALS['log']->fatal("<br><b>Sending:</b><p>To: " .$to_addr. "<br>From: " . $FromEmailAdd. "<br>From Name: " . $FromEmailName. "<br>Subject: " . $EmailSubject. "<p> " . $EmailBody . "<br>");
                $email->status = 'sent';
                $email->type = 'out';
                $email->date_sent = $now;
                $email->send();
                $email->save();
                $GLOBALS['log']->debug('EMAIL SENT:' . $email->id);
        }
    }
    return;
  }
?>

 

This is used in several logic hooks for notifications.

For example in Cases when an email is received on a certain department's queue it will notify the people in that department.

 

This has worked well from 6.x to 7.6.2.1 but after the upgrade to 7.6.2.2 the body of the email gets stripped.

 

 

        $EmailBody=<<<BODY
New email received on [CASE:{$c->case_number}] $c->name<br>
Current Case Status: $c->status<br>
Assigned to: $user->user_name<br>
From: {$email->from_addr_name} ( {$email->from_addr} )<br>
To: {$email->to_addrs}<br>
Cc: {$email->cc_addrs}<br>
Subject: $email->name<br>
See: {$sugar_config['site_url']}/#Cases/{$c->id}
<br>
<br>
{$email_text}
BODY;

 

As of 7.6.2.2

The email record in the database only contains the content of the $email_text in emails_text.description_html
while if I assign the $EmailBody to the $email->description field, it contains the full html tags included.

However, the Log entry from the sendEmail function returns the full body which makes me think that it's the 

$email->send() that somehow strips the first 10 lines. 

 

Has anyone else experienced this? have you found a solution that works for you?

Support will not look into it because it involves custom code.

 

Thank you,

Francesca

Outcomes