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= 'mldecota@plymouth.edu';

<?php
$to= 'mldecota@plymouth.edu';
$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
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;
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.