duanche2007 2015-12-03 02:07
浏览 20
已采纳

在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>

';
  • 写回答

1条回答 默认 最新

  • dongzhi2887 2015-12-03 02:35
    关注

    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>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题