NeMoD Posted June 30, 2009 Share Posted June 30, 2009 It's only sending the first value of $sessionarray, How do I make it send everything? $to = "somewhere@mail.com"; $subject = "hey"; $body = $_SESSION[$sessionarray]; if (mail($to, $subject, $body)) { echo("<p>success!</p>"); } else { echo("<p>Failed...</p>"); } Quote Link to comment https://forums.phpfreaks.com/topic/164265-solved-sending-array-through-mail/ Share on other sites More sharing options...
premiso Posted June 30, 2009 Share Posted June 30, 2009 $body = ""; if (is_array($_SESSION[$sessionarray])) { foreach($_SESSION[$sessionarray] as $key => $val) { $body .= $val . PHP_EOL; } } if (mail($to, $subject, $body)) { echo("<p>success!</p>"); } else { echo("<p>Failed...</p>"); } Quote Link to comment https://forums.phpfreaks.com/topic/164265-solved-sending-array-through-mail/#findComment-866513 Share on other sites More sharing options...
NeMoD Posted June 30, 2009 Author Share Posted June 30, 2009 I tested it and it only sends a blank message ??? <? session_start(); $sessionarray = array(number1,number2,number3); $to = "email@mail.com"; $subject = "hey"; $body = ""; if (is_array($_SESSION[$sessionarray])) { foreach($_SESSION[$sessionarray] as $key => $val) { $body .= $val . PHP_EOL; } } if (mail($to, $subject, $body)) { echo("<p>success!</p>"); } else { echo("<p>Failed...</p>"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/164265-solved-sending-array-through-mail/#findComment-866581 Share on other sites More sharing options...
NeMoD Posted June 30, 2009 Author Share Posted June 30, 2009 Sorry for the double post, but it seems I can't edit my post twice. You're script is working now, I didn't put the $_SESSION in when I declared the array. So onto my next problem: How do I fill this array, $_SESSION[$sessionarray]? foreach ($contents as $product_id=>$qty) { $sql = "SELECT * FROM product_listing WHERE product_id = '$product_id'"; $result = $db->query($sql); $row = $result->fetch(); $_SESSION[$sessionarray] = $product_id; // here we go extract($row); $output[] = '<tr>'; $output[] = '<td><img src="/images/uploads/'.$image.'" width="165" height="124" />'; $output[] = '<td><a href="cart.php?action=delete&product_id='.$product_id.'" class="r">Remove</a></td>'; $output[] = '<td><input type="text" name="qty'.$product_id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '</tr>'; $output[] = $_SESSION[$sessionarray].'</br>'; //test } Quote Link to comment https://forums.phpfreaks.com/topic/164265-solved-sending-array-through-mail/#findComment-866609 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.