<!DOCTYPE html>
<html>
<head>
<title>MY Database</title>
</head>
<body>
<?php
$dbcon=mysql_connect("localhost","santu_dbuser","santulan@123") or die("mysql connection error".mysql_error());
mysql_select_db("santu_db",$dbcon) or die("mysql database error".mysql_error());
$qry="SELECT DISTINCT CaseId,eemp_id, MAX(FeedbackDate) from session_feedback_master WHERE added_by like 'USER' GROUP BY CaseId";
$result=mysql_query($qry) or die("mysql query error".mysql_error());
ini_set("SMTP","localhost");
ini_set("smtp_port","25");
ini_set('sendmail_from', 'no.reply@santulan.co.in');
$num=mysql_num_rows($result);
if($num>0)
{
?>
<table border="1px">
<tr>
<td>Case Id</td>
<td>Feedback Date</td>
<td>Emp Id</td>
<td>Email</td>
</tr>
<?php
while($row=mysql_fetch_assoc($result))
{
echo "<tr>";
echo "<td>".$row["CaseId"]."</td>";
echo "<td>".$row["MAX(FeedbackDate)"]."</td>";
echo "<td>".$row["eemp_id"]."</td>";
echo "</tr>";
<!--- for calculation--->
$mydate=new DateTime($row["MAX(FeedbackDate)"]);
$eemp_id=$row["eemp_id"];
echo $eemp_id;
$now=new DateTime('today');
echo "Diffrence in days";
echo $datediff = $now->diff($mydate)->d;
//echo "<br>";
if($datediff>10)
{
echo "we are checking";
$eemp_id=$row["eemp_id"];
$qry="SELECT email FROM end_employee_master where id=".$eemp_id ;
$result1=mysql_query($qry) or die("mysql query error".mysql_error());
$num=mysql_num_rows($result1);
echo $num;
if($result1)
{
while($row=mysql_fetch_array($result1))
{
$eemp_id=$row["eemp_id"];
echo "employee id is". $eemp_id;
echo "<tr>";
echo "<td>".$row[0]."</td>";
//echo "<td>".$row["id"]."</td>";
//$id=$row["id"];
$to = $row[0];
echo " we found mail id".$to;
$subject = "This is subject";
$message = "This is simple text message from santulan regarding you have not "
."replied for the E-counseling chat for last 28 days ";
$from = "no.reply@santulan.co.in";
$header = 'From: '.$from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
$retval = mail($to,$subject,$message,$header);
if( $retval == true )
{
echo "result found";
echo "Message sent successfully from live.... $mail";
}
else
{
echo "Message could not be sent...";
}
echo "</tr>";
echo "no of rows: $num";
echo "Mail is: $mail";
}
}
else
{
echo " no record found";
}
}
else
{
echo "Date difference not greater ";
}
}
}
?>
</table>`enter code here`
</body>
当我将此文件放在cron并且我为警报设置我的邮件ID时,我收到以下maul错误:
/home/santu/public_html/cron_job.php:第1行:意外令牌附近的语法错误
newline' /home/santu/public_html/cron_job.php: line 1:
&#39;
当我手动运行文件时,文件运行完全正确。看起来好像有一些html错误,但我无法得到它。
答案 0 :(得分:0)
它确实取决于你的cron作业如何正常设置..
你无法通过顶部的
运行一个cron作业<!DOCTYPE html>
<html>
<head>
<title>MY Database</title>
</head>
<body>
你需要
#! /usr/bin/php
(根据需要替换php的路径)
否则unix并不认为它是一个可行的脚本以及运行它的内容 - 它并不关心它最后说.php
您还需要记住,当您从命令行运行时,cron可能没有获取您拥有的所有环境变量。
所以即使你把它作为/ usr / bin / php运行myfile.php
它可能无法正常工作,因为命令可能不在您之前的路径中。
另外 - 它输出html因为你已经编码了html。如果你不打算从你的网站运行这个文件 - 那么就不要编码来这样做。您可以输出更好的纯文本,通常通过电子邮件发送给您。