Question

In my code, I want to include while loop to fetch info from DB & send it in a table form to user. I tried to search numerous articles but no solutions worked for me actually. Here's my code:

$message->setBody('
<html>
<body>
<table style="margin-top:10px; width: 680px; border:0px;">
<tr>
    <th width="80%">Product Details</th>
    <th width="20%">Amount</th>
</tr>'); /* This is Line 43 */
while ($row = mysql_fetch_array($results2)){
$message->setBody .= ('<tr>
    <th width="80%">'.$row["product_name"].'&nbsp-&nbsp'.
                      $row["quantity"].'&nbsp'.$row["type"].'</th>
    <th width="20%">&#8377;&nbsp;'.$row["subtotal"].'</th>
</tr>');
}
$message->setBody .= ('</table>
</body>
</html>',
'text/html');

Error that is coming with this is:

Parse error: syntax error, unexpected ';' in /home/public_html/example.com/
test.php on line 43

I know I must be missing something basic but not able to find out. Any help will be appreciated.

EDIT

Results are coming fine from while loop (tested outside email), so that can not be the issue.

ERROR IN LAST PART

$message->setBody .= ("</table>
</body>
</html>",
'text/html');

Error is " 'Unexpected ',' in file at line no. 62 ".

Was it helpful?

Solution

Firstly, you have some syntax errors in your code. One place you are calling $message->setBody as function and one place you use it as object property. Secondly, if have below working version for you. Last, in future - read more carefully you code and try to understand what are you doing during developing. Your code has parts that doesn't make any sense.

<?php 

$html = "
    <html>
        <body>
            <table style='margin-top:10px; width: 680px; border:0px;'>
                <thead>
                    <tr>
                        <th width='80%'>Product Details</th>
                        <th width='20%'>Amount</th>
                    </tr>
                </thead>
                <tbody>";
while ($row = mysql_fetch_array($results2)) {
    $html .= "
                    <tr>
                        <td width='80%'>{$row["product_name"]}&nbsp-&nbsp{$row["quantity"]}&nbsp{$row["type"]}</td>
                        <td width='20%'>&#8377;&nbsp;{$row["subtotal"]}</td>
                    </tr>";
}
$html .= "
                </tbody>
            </table>
        </body>
    </html>";
$message->setBody($html, "text/html");

?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top