I had a similar error and i managed to solve it by cleaning up my HTML.
In my case there were missing "concatenators" (.) on the tr rows. Check row 2 in the example below, there is no dot (.) before the equal sign that can result in such an error.
$tbl = '<table border="0" cellpadding="5">';
$tbl = '<tr style="text-align:justify;">'."\n";
$tbl .= '<td style="width: 100%;"></td>'."\n";
$tbl .= '</tr>';
$tbl .= '</table>'."\n";
The correct version will be
$tbl = '<table border="0" cellpadding="5">';
$tbl .= '<tr style="text-align:justify;">'."\n";
$tbl .= '<td style="width: 100%;"></td>'."\n";
$tbl .= '</tr>';
$tbl .= '</table>'."\n";
Also ensure that when you are trying to format your tables and create separate rows outside the main table these rows must not be stand alones but should be inside tags and then you use then as sub-tables inside the main table.
Wrong version:
$subtbl = '<tr style="text-align:justify;">'."\n";
$subtbl .= '<td style="width: 100%;>Scores 1</td>'."\n";
$subtbl .= '<td style="width: 100%;>Scores 2</td>'."\n";
$subtbl .= '</tr>';
$maintbl = '<table border="0" cellpadding="5">';
$maintbl .= '<tr style="text-align:justify;">'."\n";
$maintbl .= '<td style="width: 100%;>'.$tbl.'</td>'."\n";
$maintbl .= '</tr>';
$maintbl .= '</table>';
Correct version:
$subtbl = '<table border="0" cellpadding="5">';
$subtbl .= '<tr style="text-align:justify;">'."\n";
$subtbl .= '<td style="width: 50%;>Scores 1</td>'."\n";
$subtbl .= '<td style="width: 50%;>Scores 2</td>'."\n";
$subtbl .= '</tr>';
$subtbl .= '</table>';
$maintbl = '<table border="0" cellpadding="5">';
$maintbl .= '<tr style="text-align:justify;">'."\n";
$maintbl .= '<td style="width: 100%;>'.$tbl.'</td>'."\n";
$maintbl .= '</tr>';
$maintbl .= '</table>'