【问题标题】:Using while loop to fetch details in Swift Mailer使用 while 循环在 Swift Mailer 中获取详细信息
【发布时间】:2014-03-26 06:01:19
【问题描述】:

在我的代码中,我想包含 while 循环以从数据库中获取信息并以表格形式将其发送给用户。 我试图搜索大量文章,但实际上没有任何解决方案对我有用。 这是我的代码:

$message->setBody('
<html>
<body>
<table style="margin-top:10px; width: 680px; border:0px;">
<tr>
    <th width="80%">Product Details</th>
    <th width="20%">Amount</th>
</tr>'); /* This is Line 43 */
while ($row = mysql_fetch_array($results2)){
$message->setBody .= ('<tr>
    <th width="80%">'.$row["product_name"].'&nbsp-&nbsp'.
                      $row["quantity"].'&nbsp'.$row["type"].'</th>
    <th width="20%">&#8377;&nbsp;'.$row["subtotal"].'</th>
</tr>');
}
$message->setBody .= ('</table>
</body>
</html>',
'text/html');

随之而来的错误是:

Parse error: syntax error, unexpected ';' in /home/public_html/example.com/
test.php on line 43

我知道我一定遗漏了一些基本但无法找到的东西。任何帮助将不胜感激。

编辑

while 循环的结果很好(在电子邮件外部测试),所以这不是问题。

上一部分有错误

$message->setBody .= ("</table>
</body>
</html>",
'text/html');

错误是“'Unexpected ',' in file at line no. 62”。

【问题讨论】:

    标签: php email swiftmailer


    【解决方案1】:

    首先,您的代码中有一些语法错误。一个地方你调用 $message->setBody 作为函数,一个地方你用它作为对象属性。其次,如果您有以下工作版本。最后,在未来 - 更仔细地阅读您的代码并尝试了解您在开发过程中在做什么。您的代码中有没有任何意义的部分。

    <?php 
    
    $html = "
        <html>
            <body>
                <table style='margin-top:10px; width: 680px; border:0px;'>
                    <thead>
                        <tr>
                            <th width='80%'>Product Details</th>
                            <th width='20%'>Amount</th>
                        </tr>
                    </thead>
                    <tbody>";
    while ($row = mysql_fetch_array($results2)) {
        $html .= "
                        <tr>
                            <td width='80%'>{$row["product_name"]}&nbsp-&nbsp{$row["quantity"]}&nbsp{$row["type"]}</td>
                            <td width='20%'>&#8377;&nbsp;{$row["subtotal"]}</td>
                        </tr>";
    }
    $html .= "
                    </tbody>
                </table>
            </body>
        </html>";
    $message->setBody($html, "text/html");
    
    ?>
    

    【讨论】:

    • 最后一部分的问题,$message->setBody .= ("
    猜你喜欢
    • 2016-04-17
    • 1970-01-01
    • 2016-02-24
    • 1970-01-01
    • 1970-01-01
    • 2019-08-04
    • 1970-01-01
    • 1970-01-01
    • 2014-11-30
    相关资源
    最近更新 更多