Estou preso ao enviar e-mail no formato correto de cron
jobs executando meu script php
, que busca registros de mysql
database.
Eu tenho um script php
que busca registros do banco de dados e processa em <html>
format quando o echod no navegador como
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
no meu script php eu uso mail simples () e para enviar e-mail eu uso cabeçalhos como
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
mail("[email protected]",$subject,$message);
eu configurei meu cron job digitando como
crontab -e //which opens 'VI' editor
ai eu configurei
MAILTO="[email protected]"
10 * * * * php /var/www/html/xyz/myfile.php
enviando e-mails a cada hora após 10 min, mas o formato não funciona. O envio de mensagens é feito em um formato como
<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>
como posso enviar e-mail no formato correto, como mostrado quando ele ecoa no navegador? e como posso configurar o cron para enviar e-mail de 13:00 a 23:00.
meu 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' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $msg);
?>
por favor ajude