php 中的 Cron 作业错误
Cron job error in php
<!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: line 1: syntax error near unexpected token newline' /home/santu/public_html/cron_job.php: line 1:
'
当我 运行 它 manually.It 时,文件 运行 绝对正确,看起来主要有一些 html 错误,但我无法得到它。
这确实有点取决于您的 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。如果您不打算从您的网站 运行 宁这个文件 - 然后不要编码它这样做。您可以让它输出更好的纯文本,通常会在任何输出中通过电子邮件发送给您。
<!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: line 1: syntax error near unexpected token
newline' /home/santu/public_html/cron_job.php: line 1:
'
当我 运行 它 manually.It 时,文件 运行 绝对正确,看起来主要有一些 html 错误,但我无法得到它。
这确实有点取决于您的 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。如果您不打算从您的网站 运行 宁这个文件 - 然后不要编码它这样做。您可以让它输出更好的纯文本,通常会在任何输出中通过电子邮件发送给您。