dtjwov4984 2012-09-08 08:29
浏览 55
已采纳

PHP使用循环数据发送电子邮件

Hi I want to send loop data with php mail function here is my code:

foreach ($data['query'] as $row){
    echo $row->name;
    echo "<br>";
    echo $row->time;
    echo "<br>";
    echo $row->dosage;
    echo "<br>";
    echo $row->frequency;
    echo "<br>";
    echo $row->quantity;
    echo "<br>";
}

$to = "somebody@example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com";
mail($to,$subject,$txt,$headers);

Can anybody told me how I can attach foreach loop data to email message body, I mean instead of sending this text (Hello World!) in body I want to send loop data.

  • 写回答

4条回答 默认 最新

  • dongxun7962 2012-09-08 08:32
    关注

    Concatenate the $txt:

    $txt = "";
    foreach ($data['query'] as $row){
        $txt .= $row->name;
        $txt .= "<br>";
        $txt .= $row->time;
        $txt .= "<br>";
        $txt .= $row->dosage;
        $txt .= "<br>";
        $txt .= $row->frequency;
        $txt .= "<br>";
        $txt .= $row->quantity;
        $txt .= "<br>";
    }
    
    $to = "somebody@example.com";
    $subject = "My subject";
    $headers = "From: webmaster@example.com";
    mail($to,$subject,$txt,$headers);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型