Java 邮件脚本需要每小时运行一次,但cron不起作用

Java 邮件脚本需要每小时运行一次,但cron不起作用,java,php,cron,sleep,Java,Php,Cron,Sleep,下面是完整的代码。当我通过浏览器调用它时,它会工作。但是,我无法让我的Cron作业运行它。我已经尝试提出了任何解决方案,并且愿意接受任何想法,可以说,这些想法将使这个脚本每小时24/7 365启动一次 信息: 霍斯盖特 PHP5.4 Hostgator Cron命令的链接: 我尝试了以下方法: 在执行这些操作时,我尚未让it将销售添加到数据库或发送一封电子邮件: /opt/php54/bin/php/home1/user/public_html/Sales/scripts/Sales-no

下面是完整的代码。当我通过浏览器调用它时,它会工作。但是,我无法让我的Cron作业运行它。我已经尝试提出了任何解决方案,并且愿意接受任何想法,可以说,这些想法将使这个脚本每小时24/7 365启动一次

信息:

  • 霍斯盖特
  • PHP5.4
  • Hostgator Cron命令的链接:
我尝试了以下方法:

在执行这些操作时,我尚未让it将销售添加到数据库或发送一封电子邮件:

  • /opt/php54/bin/php/home1/user/public_html/Sales/scripts/Sales-notif_em.php
    -无法打开输入文件:/home1/user/public_html/scripts/Sales-notif_em.php
  • php/home1/user/public_html/Sales/scripts/Sales-notif_em.php
    -空白电子邮件,仅显示以下内容:内容类型:text/html
  • php-q/home1/lotscav1/public\u html/Sales/scripts/Sales\u notif\u em.php
    -我当然没有收到来自系统的任何电子邮件
  • /usr/bin/curl home1/user/public\u html/scripts/sales-notif\u em.php
    -curl:(3)格式错误
  • 任何命令(如php或/usr/bin/curl)的后半部分带有-在尝试添加Cron作业时都会导致JSON错误
我检查了以下事项:

  • 文件权限为655
  • 客户表下的时间戳不到一小时
这是我的密码:

<?php
//find out current time and 1 hour ago
date_default_timezone_set('America/New_York');
$current_time = strtotime("now");
$hour_ago = strtotime('-1 hour');

//////////////////////////////////////////////////////////////////
/////////////////l// Connect to Sales Database  ///////////////////
//////////////////////////////////////////////////////////////////

$mysqli_s = new mysqli("localhost", "user", "password", 
"server_sales_data");
if ($mysqli_s->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli_s->connect_errno . ") 
" . $mysqli_s->connect_error;
}

//////////////////////////////////////////////////////////////////
///////////////////// Connect to EM Database  ////////////////////
//////////////////////////////////////////////////////////////////

$mysqli_em = new mysqli("localhost", "user", "password", 
"server_dlgEM");
if ($mysqli_em->connect_errno) {
echo "Failed to connect to MySQL_EM: (" . $mysqli_em->connect_errno . 
") " . $mysqli_em->connect_error;
}

//Grab store name
$dlg_store = "EM";

$em_request = "SELECT * FROM customers WHERE date BETWEEN '$hour_ago' 
AND '$current_time'";
$em_result = mysqli_query($mysqli_em, $em_request) or die("Error No 
Sales EM");
while ($em_row = mysqli_fetch_array($em_result)) {
$em_prod_num = $em_row["prod_num"];
$em_receipt = $em_row["receipt"];


//////////////////////////////////////////////////////////////////
///////////////////// Grab info for EM Sales  ////////////////////
//////////////////////////////////////////////////////////////////

$request_s = "SELECT * FROM all_products WHERE 
dlgprod_num='$em_prod_num' AND dlg_store='$dlg_store'";
$result_s = mysqli_query($mysqli_s, $request_s) or die("Error dlg 
prod num EM");
while ($row_s = mysqli_fetch_array($result_s)) {
        $sku_s = $row_s["sku"];
        $dlgprod_num_s = $row_s["dlgprod_num"];
        $book_title_s = addslashes($row_s["book_title"]);
        $dlgprod_price_s = $row_s["dlgprod_price"];
        $author_name_s = addslashes($row_s["author_name"]);
        $author_email_s = $row_s["author_email"];
        $publisher_s = $row_s["publisher"];
        $dlg_store_s = $row_s["dlg_store"];

            $add_sql_s  = "INSERT INTO all_author_sales SET
            `sku`='$sku_s', 
            `dlgprod_num`='$dlgprod_num_s',
            `dlgprod_nam`='$book_title_s',
            `dlgprod_price`='$dlgprod_price_s',
            `author_name`='$author_name_s',
            `author_email`='$author_email_s',
            `publisher`='$publisher_s',
            `dlg_store`='$dlg_store_s',
            `dlgcustomer_receipt`='$em_receipt' ";  

//create signature
$sig = "The Admin Team at www.website.com";
//to
$admin_email = "admin@website.com";
$to = array($author_email_s, $admin_email);

//setup email headers
$headers='From: ' . $admin_email . "\r\n" .
'Reply-To: ' . $admin_email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= $emailbody."\n\n";

//email subject and body
$subject = "Your book stats";
$message = "
Hi $author_name_s,<br />
I just wanted to send you a message and let you know that the book or 
books below have just been purchased.<br /><br />

Store: $dlg_store_s<br />
Receipt: $em_receipt<br />
Sku Number: $sku_s<br /><br />

Book Title: $book_title_s<br />
Publisher: $publisher_s<br />
Product Number: $dlgprod_num_s<br />
Price: $dlgprod_price_s<br /><br />

Sincerely,<br />
$sig<br /><br />

To remove yourself from this notification, please send an email to 
$admin_email with Unsubscribe in the subject line.
";

            if ($mysqli_s->multi_query($add_sql_s) === TRUE) {
            mail (implode(',', $to), $subject, $message, $headers); 
            } else {
                echo "Error: " . $add_sql_s . "<br>" . $mysqli_s-
>error . "<br>" . $string;
            }


    }



}


?>

我打赌您要执行的php文件路径错误

如果可以,请尝试使用终端,导航到文件所在的文件夹,然后尝试通过命令行从该文件夹运行该文件

还请注意,您指的是两个不同的名称:sales-notif_em.php和sales-notif_me.php。

(代表OP发布)

谢谢你的帮助。出于测试目的,我用我的电子邮件作为作者制作了一个定制产品。在客户表中,我插入了产品111111和11111 0。然而,在所有的_产品中,我给出了产品11111111和11111110。最终的结果是我犯了一个错误


我希望你能从这次活动中学到一些东西。知识比我的自我更重要。谢谢大家!

我正在再次查看文件路径。对不起,这两个不同的文件。我有3个文件,每个数据库一个。sales-notif\u me,sales-notif\u em,sales-notif\u lc。只是em就是我正在测试的那个。路径是正确的,因为如果不是,它会说找不到文件。我使用路径Sale将sales作为子域。在将文件夹名称更改为小写后,我确实重做了子域,以使其更简单。我正在进行一些更改以进行故障排除,因此我将随时向您通报。请尝试逐步升级到您的完整脚本,以查看错误所在。从一个新文件开始,简单地记录一些东西,然后进行查询和记录…继续填写步骤,直到出错为止,您将确切地知道是什么原因造成的。谢谢!故障排除101 lol。我总是试图把简单的事情先复杂化,然后忘记。请花几分钟时间尝试这里的降价格式,特别是内联代码格式和无序列表(“要点”),因为它使事情变得非常容易阅读,并减少了自愿编辑工作。谢谢(猜测一下,这可能是你投反对票的原因)。