开发者

Sending array or session values in PHP mail

I have a session array that I want to send the contents of in an email body.

$_SESSION['order'] is my session value and print_r[$_SESSION['order']] gives me output like the following:

Array 
( 
    [0] => Array 
        开发者_运维技巧   ( 
               [0] => product one 
               [1] => 1 
           ) 
    [1] => Array 
           ( 
               [0] => product two 
               [1] => 1 
           ) 
    [2] => Array 
           ( 
               [0] => product three 
               [1] => 1 
           ) 
) 

This session value I have is a 2D array and I need get this session data.

Here's what I have in my email body:

$Body="<b>Oder Details</b>  
<table> 
foreach($order as $row)  
{  
echo '<tr>';  
echo '<td>$row[0]</td>';  
echo '<td>$row[1]</td>';  
echo '</tr>';  
}  </table>"

But all I am getting in the email is blank except for this text:

Order Details   
foreach(Array as ) {
}

Why am I getting blank emails even though $_SESSION contains values? Is my foreach loop wrong?


I'll shoot a wild guess here, but I think that the correct way to build your email is:

$body = "<b>Oder Details</b>";
$body .= "<table>";

foreach($order as $row)
{
 $body .= "<tr>";
 $body .= "<td>$row[0]</td>";
 $body .= "<td>$row[1]</td>";
 $body .= "</tr>";
} 

$body .= "</table>";

I think that the problem is that your loop is inside the string quotes. Just a thought.


Check this PHP manaul page about Arrays:-

http://php.net/manual/en/language.types.array.php

Determine which way to use when getting elements from Array as there are different ways like Indexed and Associative array types plus that some functions may make the array empty when retrieving the array elements like mysql_fetch_assoc()

I hope this helps you..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜