$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: testing <test@gmail.com>' . "\r\n";
$subject = "testing";

$content = "

//html content

question How to use foreach loop inside this ?

";

$sent=mail("test@gmail.com",$subject,$content,$headers);

You use it outside and just add the variable that carries the result of the loop, for example:

$rows = '';

foreach($result as $row)
    $rows .= "
        <tr>
            <td>{$row['article']}</td>
            <td>{$row['price']}</td>
        </tr>
    ";

$content = "

    <p>Display order list:</p>

    <table>
        <thead>
            <tr>
                <th>Item</th>
                <th>Price</th>
            </tr>
        </thead>
        <tbody>
            {$rows}
        </tbody>
    </table>

";

Please: next time define the question outside the code block.

its for an invoice so the foreach part must create again and again.So its not possible to use the foreach outside

thank you brooooooooooooooo........Its working