The code below generates an HTML email upon user submit. The email is sent successfully, but the problem I am having is displaying the contents of an array which will contain 1 or more values.
Initially, the user clicks 1 or more checkboxes to get the container numbers. You will see the variable for containerNumber below, which is in an array. The user also manually enters the trucker email which is also turned into a PHP variable. The username is stored in a session is also converted into another PHP variable.
<?php
$containerArray = explode(',', $_POST['containerNumber']);
$trucker_email = mysql_real_escape_string(stripslashes($_POST['trucker_email']));
$username = $_SESSION['username'];
Now I generate the variables for the email:
$to = $trucker_email;
$subject = 'Container Numbers';
$headers = "From: " . $username . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$message = "You have received a message with Containter Numbers:<br />";
$message .= "Greetings " . stripslashes($_POST['trucker_name']) . "<br />";
Now here's the part that I am trying to get working. It's the HTML table that should show each container number in it's own table cell:
$message .= '<html><body>';
$message .= '<table rules="all" style="border-color: #62c462" cellpadding="10">';
$message .= '<tr style="background: #8DBFCF;"><th>Containers</th></tr>';
$message .= print_r($containerArray, true);
$message .= '</table>';
$message .= '<body></html>';
@mail($to, $subject, $message, $headers);
?>
I send an email to myself, and when I view it, the array values are displayed like this:
ContainersArray ( [0] => CMAU123456 [1] => TRLU1234567 )
This is not how I want it displayed. I know I have to use a foreach loop to get this to work properly, but I am not sure how or where to start the loop.
Please help.
<table><tr><td>foo</td></tr></table>is ok,<table>foo</table>is invalid.