I am stuck when sending email in correct format from cron
jobs executing my php
script which fetches records from mysql
database.
i have a php
script which fetches records from database and renders in <html>
format when echod in browser like
StartTime EndTime Count User Count Apps
12:00:00 12:59:59 0 0
01:00:00 01:59:59 0 0
02:00:00 02:59:59 0 0
03:00:00 03:59:59 0 0
04:00:00 04:59:59 0 0
05:00:00 05:59:59 0 0
06:00:00 06:59:59 0 0
07:00:00 07:59:59 0 0
08:00:00 08:59:59 0 0
in my php script i use simple mail() and to send mail i use headers like
$headers = 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=utf-8' . "
";
mail("[email protected]",$subject,$message);
i set my cron job by typing like
crontab -e //which opens `VI` editor
there i set
MAILTO="[email protected]"
10 * * * * php /var/www/html/xyz/myfile.php
its sending mail every hour past 10 min but the format goes wrong.its sending mail in a format like
<html><head><title>Count User Info TimeWise</title></head><h2>Count User/Application in CurrentDate</h2><body><table border="3" cellspacing="2">
<tr><th>StartTime</th><th>EndTime</th><th>Count User</th><th>Count Apps</th>
</tr><tr><td>12:00:00</td><td>12:59:59</td><td>1</td><td>1</td></tr><tr>
<td>13:00:00</td><td>13:59:59</td><td>2</td><td>2</td></tr><tr><td>14:00:00</td>
<td>14:59:59</td><td>2</td><td>2</td></tr><tr><td>15:00:00</td><td>15:59:59</td>
<td>2</td><td>2</td></tr><tr><td>16:00:00</td><td>16:59:59</td><td>2</td><td>2</td>
</tr><tr><td>17:00:00</td><td>17:59:59</td><td>2</td><td>2</td></tr><tr>
<td>18:00:00</td><td>18:59:59</td><td>2</td><td>2</td></tr><tr><td>19:00:00</td>
<td>19:59:59</td><td>2</td><td>2</td></tr><tr><td>20:00:00</td><td>20:59:59</td>
<td>1</td><td>1</td></tr><tr><td>21:00:00</td><td>21:59:59</td><td>0</td><td>0</td>
</tr><tr><td>22:00:00</td><td>22:59:59</td><td>0</td><td>0</td></tr></body>
</table></html>
how can i send mail in the correct format like shown when its echoed in browser?and how can i set cron to send email from 1pm to 11pm .
my php
script
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("dbname",$con);
$to="[email protected]"
$subject = 'Count User Login And Application';
//fetch between 06:00:00 to 08:30:00 09:00:00 to 10:00:00
$date=array('06:00:00','09:00:00');
$date1=array('08:30:00','10:00:00');
$msg = '<html><head>';
$msg .='<title>Some Title</title>';
$msg .='</head>';
$msg .='<h1>Test User</h1>';
$msg .='<table border="1" cellspacing="1">';
$msg .= "<tr>";
$msg .= "<th>start time</th>";
$msg .= "<th>end time</th>";
$msg .= "<th>Count</th>";
$count=count($date);
for($i=0;$i<$count;$i++){
$sql="SELECT count(*) AS test FROM table_name WHERE DATE_FORMAT(sys_time,'%H:%m:%i') BETWEEN DATE_FORMAT(sys_time,'$date[$i]') AND DATE_FORMAT(sys_time,'$date1[$i]') ";
$query=mysql_query($sql);
if(!$query){
die('could not connect'.mysql_error());}
while($row=mysql_fetch_array($query)) {
$msg .= "<tr>";
$str=$row['test'];
$subcategory = explode(',', $str);
foreach($subcategory as $value)
{
$msg .= "<td>" . $value . "</td>";
}
$msg .= "</tr>";
}
}
$msg .= "</table>";
$msg .= "</html>";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";
mail($to, $subject, $msg);
?>
please help