1

I have a PHP script through which I send HTML emails. I'm using a 'for' loop to collect data and storing it in a variable. The loop is instructed to run 25 times. The problem is that it is looping only 19 times. I checked for any unlcosed tags or typos in syntax but didn't find any. I'm posting the for loop section in case any of you can spot what I couldn't. It is really frustrating as I think the solution is very simple and yet I'm unable to spot the problem.

My headers for the 'mail()' function are fine. Here they are just in case

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

And here is my for loop:

$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>";

I can attach the screenshot of the email that is being sent to give an idea on how the code is breaking. Let me know if you want the screenshot too.

PS : I copy-pasted this code in a separate file and ran it and it was working fine. The loop iterated 25 times. This makes me believe that there is a problem putting it inside HTML email.

Also adding in the email script if that helps:

$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);

Thanks in advance, Nisar

8
  • in for loop after $abc .="<tr>"; echo $i .. so that you can have exact idea that what is the value of $i when loop is completely executed. Commented Apr 16, 2012 at 11:31
  • Ok Slayer. I'll do that right now and let you know in a minute. EDIT : It is showing 19. So the loop is breaking. Commented Apr 16, 2012 at 11:35
  • what is the value of i .. is that continuous from 1-19 or something else? Commented Apr 17, 2012 at 4:27
  • well I run your code in my system . loop runs continuously for 25. Commented Apr 17, 2012 at 5:22
  • That is what I get too. When I echo $abc on submission of form, I see all 25 rows on the php page. But the same $abc is showing only 19 rows in the email. This makes me believe that something is messed up in the email script because $abc is working fine. Commented Apr 17, 2012 at 5:24

1 Answer 1

1

Nevermind, I found what was wrong. Here it is for people with similar problems.

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.