Jump to content

Mail does not send everything


MikhailGrymkabin

Recommended Posts

Hi, my code seemingly will not send the table data through email, the Table headers are sent fine, but anything after the while loop does not get sent, looking to remedy this issue.[ic]$to= '[email protected]';

<?php
$to= '[email protected]';
$sub = "Hi";
$header = "Content-type: text/html";
$con = mysql_connect('localhost', 'sysop', 'Rotten210');
if (!$con){
die('could not connect' . mysql_error())
;
}
$db_selected = mysql_select_db('mldecota', $con);
if (!$db_selected) {
die ('Borked ' . mysql_error());
}
$result = mysql_query('SELECT * FROM data');
if (!$result) {
die('Invalid query: ' . mysql_error());
}
echo'completed succesfully';
echo "<table border='1'>
<tr>
<th>Date</th>
<th>Time</th>
<th>Machine</th>
<th>Action</th>
<th>User</th>
</tr>";
while($row = mysql_fetch_array($result))
 
{
echo "<tr>";
echo "<td>" . $row['Date'] . "</td>";
echo "<td>" . $row['Time'] . "</td>";
echo "<td>" . $row['Machine'] . "</td>";
echo "<td>" . $row['Action'] . "</td>";
echo "<td>" . $row['USER'] . "</td>";

echo "</tr>";
}

echo "</table>";
$msg = "<table border='1'>
       <tr>
       <th>Date</th>
       <th>Time</th>
       <th>Machine</th>
       <th>Action</th>
       <th>User</th>
       </tr>";

while($row1 = mysql_fetch_array($result)){
$msg.= "<tr>";
$msg.= "<td>" . $row1['Date'] . "</td>";
$msg.= "<td>" . $row1['Time'] . "</td>";
$msg.= "<td>" . $row1['Machine'] . "</td>";
$msg.= "<td>" . $row1['Action'] . "</td>";
$msg.= "<td>" . $row1['USER'] . "</td>";
$msg.= "</tr>";
}
$msg .= "</table>";

mail($to,$sub,$msg,$header);
mysql_close($con);
?> 
<?php
	phpinfo();
?>

Link to comment
https://forums.phpfreaks.com/topic/283637-mail-does-not-send-everything/
Share on other sites

Why run the same query twice. Just build the table in a variable, then echo and send the same variable:

 

$table = "<table border='1'>
<tr>
<th>Date</th>
<th>Time</th>
<th>Machine</th>
<th>Action</th>
<th>User</th>
</tr>";
while($row = mysql_fetch_array($result))
{
	$table . = "<tr>";
	$table . = "<td>" . $row['Date'] . "</td>";
	$table . = "<td>" . $row['Time'] . "</td>";
	$table . = "<td>" . $row['Machine'] . "</td>";
	$table . = "<td>" . $row['Action'] . "</td>";
	$table . = "<td>" . $row['USER'] . "</td>";

	$table . = "</tr>";
}
$table . = "</table>";

echo $table;
$msg = $table;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.