PHP for循环不完全在HTML电子邮件中迭代

时间:2012-04-16 11:27:52

标签: php html for-loop

我有一个PHP脚本,通过它我可以发送HTML电子邮件。我正在使用'for'循环来收集数据并将其存储在变量中。指示循环运行25次。问题是它只循环了19次。我在语法中检查了任何未标记的标签或拼写错误但没有找到任何标签。我发布了for循环部分,以防任何人发现我无法发现的内容。这真的令人沮丧,因为我认为解决方案非常简单,但我无法发现问题。

'mail()'函数的标题很好。在这里他们只是以防万一

$headers = "From: $from \r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

这是我的for循环:

$abc ="<table width='600'>";
        $abc .= "<tr>
                        <td bgcolor='#d6bf86'><span style='color:#9c2a00'>Number of Products</span></td>
                        <td align='center' bgcolor='#fde4d0'>$pagess</td>
                        <td align='center' bgcolor='#c3deb9'>$pagese</td>
                        <td align='center' bgcolor='#bee7f8'>$pagesu</td>
                    </tr>";


        for($i=1; $i<=25; $i++)
        {
            $abc .="<tr>";
            if($i % 2 == 0)     //  EVEN ROW
            {       
                    $abc .= "<td bgcolor='#d6bf86' width='260'><span style='color:#9c2a00'>".${f.$i}."</span></td>";
            }
            else                //  ODD ROW
            {
                    $abc .= "<td bgcolor='#fffbd0' width='260'><span style='color:#9c2a00'>".${f.$i}."</span></td>";
            }

                    if(isset(${s.$i}))      
                    {
                        $abc .= "<td bgcolor='#fde4d0' align='center'>Yes</td>";
                        ${s.$i} = "Yes";
                    }
                    else
                    {
                        $abc .= "<td bgcolor='#fde4d0' align='center'>No</td>";
                        ${s.$i} = "No";
                    }
                    if(isset(${e.$i}))
                    {
                        $abc .= "<td bgcolor='#c3deb9' align='center'>No</td>";
                        ${e.$i} = "Yes";
                    }
                    else
                    {
                        $abc .= "<td bgcolor='#c3deb9' align='center'>Yes</td>";
                        ${e.$i} = "No";
                    }
                    if(isset(${u.$i}))
                    {
                        $abc .= "<td bgcolor='#bee7f8' align='center'>No</td>";
                        ${u.$i} = "Yes";
                    }
                    else
                    {
                        $abc .= "<td bgcolor='#bee7f8' align='center'>Yes</td>";
                        ${u.$i} = "No";
                    }
            $abc .="</tr>";
        }


        if(isset($_POST['dscs']))   //  DISCOUNT HAS BEEN APPLIED
        {

            $abc .= "<tr>
                            <td>Base Price</td>
                            <td align='center'>$sums</td>
                            <td align='center'>$sume</td>
                            <td align='center'>$sumu</td>
                        </tr>";
            $abc .= "<tr>
                            <td>Discount Offered</td>
                            <td align='center'>$discount% </td>
                            <td align='center'>$discount% </td>
                            <td align='center'>$discount% </td>
                        </tr>";
            $abc .= "<tr>
                            <td>Effective Price</td>
                            <td align='center'>$dscs</td>
                            <td align='center'>$dsce</td>
                            <td align='center'>$dscu</td>
                      </tr>";
        }
        else
        {
            $dscs = $sums;
            $dsce = $sume;
            $dscu = $sumu;
            $abc .= "<tr>
                            <td>Total Price</td>
                            <td align='center'>$sums</td>
                            <td align='center'>$sume</td>
                            <td align='center'>$sumu</td>
                        </tr>";
        }

        $abc .="</table>";

我可以附上正在发送的电子邮件的屏幕截图,以便了解代码是如何破解的。如果您也想要截图,请告诉我。

PS:我将此代码复制粘贴到一个单独的文件中并运行它并且工作正常。循环迭代25次。这让我相信将它放在HTML电子邮件中会有问题。

如果有帮助,还可以添加电子邮件脚本:

$to = $clem;
$subject = "Something goes here";
$message = "<html>
<head></head>
<body style='background-color:#ffffff; font-family:Lucida Sans Unicode, Lucida Grande, sans-serif;'>
    <table width='600'>
        <tr>
            <td>$abc</td>
        </tr>
    </table>
</body>
</html>";

$from = "$logged_user";
$headers = "From: $from \r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$res=mail($to,$subject,$message,$headers);

提前致谢, 尼萨尔

1 个答案:

答案 0 :(得分:1)

没关系,我发现了什么问题。这是针对有类似问题的人。

I learnt that html emails have a 990 character limit per line. That was the reason why my code was breaking