procatmer procatmer - 2 months ago 7
PHP Question

Using loop for creating row in formatted email

i want to create a formatted email. in my email's body, i need to add loop for creating table's row. i don't know how to make it work. my loop looks like this

<?php $total = 0; for($i=0; $i<3; $i++) { ?>
<td style="padding: 8px; line-height: 20px;">col 0</td>
<td>col 1</td>
<td>col 2</td>
<td>col 3</td>
<?php }?>

it works in normal html page. but when i tried to make an email's body and pass that code to string like this,

$body = "<tbody> <?php $total = 0; for($k=0; $k<3; $k++) { ?>
<tr> <td style='padding: 8px; line-height: 20px;'>1</td>
<td>asd</td> <td>ert</td> <td>qwe</td> </tr> <?php }?> </tbody>";

send($to, $subject, $body);

in my email, it doesn't create any row at all. any advice?


Main advice is to learn php syntax.

Sample of proper code is:

$body = "<tbody>";
$total = 0; 
for($k=0; $k<3; $k++) {
    $body .= "<tr> <td style='padding: 8px; line-height: 20px;'>1</td>" 
        . "<td>asd</td> <td>ert</td> <td>qwe</td> </tr>";
$body .= "</tbody>";

send($to, $subject, $body)