douhaoqiao9304 2014-02-20 23:41
浏览 163
已采纳

在PHPMailer中的msgHTML中运行foreach循环

I want to run a foreach loop inside a msgHTML on PHP Mailer to make the table td dynamic from array. Below is the latest code I have. I' am working on dreamweaver and it show that this code has errors, I don't know how to solve this issue.

<?php
$mail->Subject = "Vacancy No: " . $vacancy_no . " - " . $vacancy_title;
$mail->MsgHTML(
"
Some html and text goes here....
Below is the main part of this topic.

<u><strong>Referees & Contact</strong></u><br/>
<table width='100%' border='0' cellpadding='0' cellspacing='0' style='border: 1px solid #E2E2E2;'>
    <tr style='background: #003e82; color: #FFF; font-weight: bold;'>
        <td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Name</td>
        <td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Position & Organization</td>
        <td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Phone Contact</td>
        <td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Email</td>
    </tr>
"
?>
    <?php
        foreach($variable as $var){
    ?>
        <tr>
            <td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Name</td>
            <td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Position & Organization</td>
            <td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Phone Contact</td>
            <td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Email</td>
        </tr>
    <?php
        }
    ?>
    <?php "
</table>
");
?>
  • 写回答

2条回答 默认 最新

  • doumicheng6732 2014-02-20 23:46
    关注

    How about this code?

    $mail->Subject = "Vacancy No: " . $vacancy_no . " - " . $vacancy_title;
    
    $msg = "Some html and text goes here....
       Below is the main part of this topic.
    
       <u><strong>Referees & Contact</strong></u><br/>
       <table width='100%' border='0' cellpadding='0' cellspacing='0' style='border: 1px solid #E2E2E2;'>
        <tr style='background: #003e82; color: #FFF; font-weight: bold;'>
          <td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Name</td>
          <td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Position & Organization</td>
          <td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Phone Contact</td>
          <td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Email</td>
        </tr>";
    
    foreach($variable as $var){
    
       $msg .= "<tr>
                <td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Name</td>
                <td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Position & Organization</td>
                <td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Phone Contact</td>
                <td style='border: 1px solid #E2E2E2; height:30px; padding-left:5px; padding-right: 5px;'>Email</td>
            </tr>";
    
    } // foreach
    
    $msg .= "</table>";
    
    $mail->MsgHTML( $msg );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 商城生产日期批次库存问题
  • ¥15 esp8266控制共阳极wrgb灯板无法关闭所有led灯
  • ¥100 python读取速度问题
  • ¥15 stm32f407使用DMA问题
  • ¥15 您好 这个API接口该怎么弄 网站搭建好了 API也有 现在就不知道该怎么填写API 不知道怎么用
  • ¥88 用uniapp写一个多端的程序,用到高德地图,用高德的JSAPI吗?
  • ¥20 关于#c++#的问题:水果店管理系统
  • ¥30 dbLinq最新版linq sqlite
  • ¥20 对D盘进行分盘之前没有将visual studio2022卸载掉,现在该如何下载回来
  • ¥15 完成虚拟机环境配置,还有安装kettle