0

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?

2
  • use <table> tag. in body . Commented Jul 28, 2016 at 7:41
  • i did use it. above is just small piece of my code to point out where exactly my problem is. Commented Jul 28, 2016 at 7:44

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

1 Comment

oh my God ! yes, you're correct. how could i forget about this. thanks for reminding me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.