procatmer procatmer - 4 months ago 8
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

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


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?

Answer

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)