在mailtext中使用php循环[mail()] [关闭]


I have to send an email for each order. I would formatting the Text a little bit and if there are more orders i would separate like this:
1 clothes 20eur
1 shoes 10eur...

At the moment looks like:
1, 1 clothes, shoes 20eur,10eur

This way i need a loop for separate them, but got error 'unexpected foreach'.

$mailtext = '
<html>
<head>
  <title>Form order</title>
</head>
<body>
<h1>Form order</h1>
<p>Details:</p>
<table border="1">
<tr>
  <td>Name</td>
  <td>Adress</td>
</tr>
<tr>
  <td>'.$name.'</td>
  <td>'.$strase.'</td>
</tr>
</table>

<p>Order:</p>
'
 foreach ($produktarr as $row){
  echo'<tr>';
    echo'<td>'.$row['amount'].'</td>';
    echo'<td>'.$row['product'].'</td>';
    echo'<td>'.$row['price'].'</td>';
  echo'</tr>';
}
'
</body>
</html>

';

Why a foreach loop inside a variable declaration? I would do something like this:

$mailtext = '
<html>
<head>
  <title>Form order</title>
</head>
<body>
<h1>Form order</h1>
<p>Details:</p>
<table border="1">
<tr>
  <td>Name</td>
  <td>Adress</td>
</tr>
<tr>
  <td>'.$name.'</td>
  <td>'.$strase.'</td>
</tr>
</table>

<p>Order:</p>
';
 foreach ($produktarr as $row){
 $mailtext.= '<tr><td>'.$row['amount'].'</td><td>'.$row['product'].'</td><td>'.$row['price'].'</td></tr>';

}
$mailtext.= '</body>
</html>';