使用while循环来获取Swift Mailer中的详细信息 [英] Using while loop to fetch details in Swift Mailer

查看:122
本文介绍了使用while循环来获取Swift Mailer中的详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中,我想包括while循环从DB&将其以表格形式发送给用户。
我试图搜索许多文章,但没有解决方案为我工作。
这是我的代码:

In my code, I want to include while loop to fetch info from DB & send it in a table form to user. I tried to search numerous articles but no solutions worked for me actually. Here's my code:

$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

我知道我一定缺少一些基本的东西,但是找不到。任何帮助将不胜感激。

I know I must be missing something basic but not able to find out. Any help will be appreciated.

编辑

结果从循环(测试外部电子邮件),这样就不能成为问题。

Results are coming fine from while loop (tested outside email), so that can not be the issue.

最后一段错误

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

错误是'意外','在文件第62行

Error is " 'Unexpected ',' in file at line no. 62 ".

推荐答案

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

Firstly, you have some syntax errors in your code. One place you are calling $message->setBody as function and one place you use it as object property. Secondly, if have below working version for you. Last, in future - read more carefully you code and try to understand what are you doing during developing. Your code has parts that doesn't make any sense.

<?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");

?>

这篇关于使用while循环来获取Swift Mailer中的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆